system - execute a shell command
#include <stdlib.h>
int system(const char *command);
The system() library function behaves as if it used
fork(2) to create a child process that executed the
shell command specified in command
using
execl(3) as follows:
execl("/bin/sh", "sh", "-c", command, (char *) NULL);
system() returns after the command has been completed.
During execution of the command, SIGCHLD will be
blocked, and SIGINT and SIGQUIT will
be ignored, in the process that calls system(). (These
signals will be handled according to their defaults inside the child
process that executes command
.)
If command
is NULL, then system() returns a
status indicating whether a shell is available on the system.
The return value of system() is one of the following:
If command
is NULL, then a nonzero value if a shell is
available, or 0 if no shell is available.
If a child process could not be created, or its status could not
be retrieved, the return value is -1 and errno
is set to
indicate the error.
If a shell could not be executed in the child process, then the return value is as though the child shell terminated by calling _exit(2) with the status 127.
If all system calls succeed, then the return value is the
termination status of the child shell used to execute command
.
(The termination status of a shell is the termination status of the last
command it executes.)
In the last two cases, the return value is a "wait status" that can be examined using the macros described in waitpid(2). (i.e., WIFEXITED(), WEXITSTATUS(), and so on).
system() does not affect the wait status of any other children.