system.3s (2010 09)
s
system(3S) system(3S)
NAME
system( ) - issue a shell command
SYNOPSIS
#include <stdlib.h>
int system(const char *command);
DESCRIPTION
system() 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
fork() (see fork (2)), and the child
process invoked the sh-posix (1) utility via a call to
execl() (see exec (2)) as follows:
execl("/usr/bin/sh", "sh", "-c", command, 0);
system()
ignores the SIGINT and SIGQUIT signals, and blocks the
SIGCHLD 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
system() and take whatever action is
appropriate to the application if the command terminated due to receipt of a signal.
system() does not affect the termination status of any child of the calling processes other than the pro-
cess or processes it itself creates.
system() does not return until the child process has terminated.
APPLICATION USAGE
If the return value of
system() is not − 1, its value can be decoded through the use of the macros
described in <sys/wait.h>. For convenience, these macros are also provided in <stdlib.h
>.
Note that, while
system() must ignore SIGINT and SIGQUIT and block SIGCHLD 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
SIGINT is being caught or is set to SIG_DFL
when system() is called, the
child is started with
SIGINT handling set to SIG_DFL.
Ignoring
SIGINT and SIGQUIT in the parent process prevents coordination problems (such as two
processes reading from the same terminal) when the executed command ignores or catches one of the sig-
nals.
RETURN VALUE
If command is null,
system() returns non-zero.
If command is not null,
system() returns the termination status of the command language interpreter
in the format specified by wait (2). The termination status of the command language interpreter is as
specified for sh-posix (1), except that if some error prevents the command language interpreter from exe-
cuting after the child process is created, the return value from system() is as if the command language
interpreter had terminated using _exit(127). If a child process cannot be created, or if the termina-
tion status for the command language interpreter cannot be obtained, system() returns − 1 and sets
errno to indicate the error.
DIAGNOSTICS
system() forks to create a child process which, in turn, exec()s /usr/bin/sh in order to execute
string . If the fork fails, system() returns −1 and sets errno. If the exec fails, system() returns
the status value returned by waitpid() (see wait (2)) for a process that terminates with a call of
exit(127).
ERRORS
If errors are encountered,
system() sets errno values as described by fork(2).
FILES
/usr/bin/sh
SEE ALSO
sh(1), fork(2), exec(2), wait(2), thread_safety(5).
STANDARDS CONFORMANCE
system(): AES, SVID2, SVID3, XPG2, XPG3, XPG4, POSIX.2, ANSI C
HP-UX 11i Version 3: September 2010 − 1 − Hewlett-Packard Company 1