system(3S)system(3S)NAMEsystem() - issue a shell command
executes the command specified by the string pointed to by command.
The environment of the executed command is as if a child process were
created using (see fork(2)), and the child process invoked the sh-
posix(1) utility via a call to (see exec(2)) as follows:
ignores the and signals, and blocks the signal, while waiting for the
command to terminate. If this might cause the application to miss a
signal that would have killed it, the application should examine the
return value from and take whatever action is appropriate to the appli‐
cation if the command terminated due to receipt of a signal.
does not affect the termination status of any child of the calling pro‐
cesses other than the process or processes it itself creates.
does not return until the child process has terminated.
If the return value of is not −1, its value can be decoded through the
use of the macros described in For convenience, these macros are also
Note that, while must ignore and and block while waiting for the child
to terminate, the handling of signals in the executed command is as
specified by fork(2) and exec(2). For example, if is being caught or
is set to when is called, the child is started with handling set to
Ignoring and in the parent process prevents coordination problems (such
as two processes reading from the same terminal) when the executed com‐
mand ignores or catches one of the signals.
If command is null, returns non-zero.
If command is not null, returns the termination status of the command
language interpreter in the format specified by wait(2). The termina‐
tion status of the command language interpreter is as specified for sh-
posix(1), except that if some error prevents the command language
interpreter from executing after the child process is created, the
return value from is as if the command language interpreter had termi‐
nated using If a child process cannot be created, or if the termination
status for the command language interpreter cannot be obtained, returns
−1 and sets to indicate the error.
forks to create a child process which, in turn, in order to execute
string. If the fork fails, returns −1 and sets If the exec fails,
returns the status value returned by (see wait(2)) for a process that
terminates with a call of
If errors are encountered, sets values as described by fork(2).
FILESSEE ALSOsh(1), fork(2), exec(2), wait(2), thread_safety(5).