WAITPID(2P) WAITPID(2P)
NAME
waitpid - wait for child process to stop or terminate
SYNOPSIS
#include <sys/wait.h>
int waitpid(statloc, options)
int *statloc, options;
DESCRIPTION
waitpid provides both non-blocking status collection and
collection of the status of children that are stopped.
If stat_loc (taken as an integer) is nonzero, 16 bits of
information called status are stored in the low order 16
bits of the location pointed to by stat_loc . status can be
used to differentiate between stopped and terminated child
processes and if the child process terminated, status
identifies the cause of termination and passes useful
information to the parent. This is accomplished in the
following manner:
If the child process stopped, the high order 8 bits of
status will contain the number of the signal that
caused the process to stop and the low order 8 bits
will be set equal to 0177.
If the child process terminated due to an exit call,
the low order 8 bits of status will be zero and the
high order 8 bits will contain the low order 8 bits of
the argument that the child process passed to exit ;
see exit (2).
If the child process terminated due to a signal, the
high order 8 bits of status will be zero and the low
order 8 bits will contain the number of the signal that
caused the termination. In addition, if the low order
seventh bit (i.e., bit 200) is set, a ``core image''
will have been produced; see signal (3).
If options is zero, the behavior of waitpid is identical to
Page 1 May 1989
WAITPID(2P) WAITPID(2P)
wait(2). Otherwise, options consists of the logical OR of
one or both of the following flags:
WNOHANG Return immediately, even if there are no children
to wait for. In this case, a return value of zero
indicates that no children have terminated (or
stopped, if WUNTRACED is also set).
WUNTRACED Return the status of stopped children. If the
child process has stopped due to the delivery of a
SIGTTIN, SIGTTOU, SIGTSTP, or SIGSTOP signal, its
status may be collected by setting this flag.
If WUNTRACED is set and the status of a stopped child
process is reported, the high order 8 bits of status shall
contain the number of the signal that caused the process to
stop and the low order eight bits shall be set to the octal
value 0177.
RETURN VALUE
waitpid returns -1 if there are no children not previously
waited for; zero is returned if WNOHANG is specified and
there are no stopped or terminated children.
ERRORS
If any of the following conditions occur, waitpid will
return -1 and set errno to the corresponding value:
[ECHILD] The calling process has no existing unwaited-
for child processes.
[EINVAL] waitpid was called with an invalid options
value.
SEE ALSO
exit(2), wait(2), wait3(2N).
Page 2 May 1989