Linux C system is used to execute shell commands in programs.
Usage
# Include <stdlib. h> <br/> // function form <br/> INT system (const char * string );
Function Description
System () calls fork () to generate sub-processes. The sub-process calls/bin/sh-C string to execute the command represented by the string parameter, after the command is executed, the original called process is returned. The sigchld signal is temporarily shelved during system () calls, while the SIGINT and sigquit signals are ignored.
Return Value
If system () fails to call/bin/sh, 127 is returned, and-1 is returned for other causes of failure. If the string parameter is a null pointer, a non-zero value is returned. If system () is successfully called, the return value after the shell command is executed is returned. However, the returned value may also be 127 returned when system () fails to call/bin/sh, therefore, it is best to check errno again to confirm the execution is successful.
Additional instructions
Do not use system () when writing programs with SUID/SGID permissions. System () inherits environment variables, which may cause system security problems.
Example
# Include <stdlib. h> <br/> main () <br/> {<br/> system ("LS-Al/etc/passwd/etc/shadow "); <br/>}< br/>