HP-UX Reference (11i v1 00/12) - 3 Library Functions N-Z (vol 7)
__________________________________________________________________________________________________________________________________________________________________________________________________
__________________________________________________________________________________________________________________________________________________________________________________________________
STANDARD Printed by: Nora Chuang [nchuang] STANDARD
/build/1111/BRICK/man3/nan.3m
________________________________________________________________
___ ___
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 appropri-
ate 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
The interface system() is thread-safe. It is not async-cancel-safe. A cancellation point may occur when
a thread is executing system().
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 execut-
ing 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 termination
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).
Section 3−−908 − 1 − HP-UX Release 11i: December 2000
___
___