HP-UX Reference (11i v1 00/12) - 2 System Calls (vol 5)
__________________________________________________________________________________________________________________________________________________________________________________________________
__________________________________________________________________________________________________________________________________________________________________________________________________
STANDARD Printed by: Nora Chuang [nchuang] STANDARD
/build/1111/BRICK/man2/!!!intro.2
________________________________________________________________
___ ___
w
wait(2) wait(2)
NAME
wait, waitpid - wait for child process to stop or terminate
SYNOPSIS
#include <sys/types.h> OH
#include <sys/wait.h>
pid_t wait(int *stat_loc);
pid_t waitpid(pid_t pid, int *stat_loc, int options);
DESCRIPTION
The wait() and waitpid() functions allow the calling process to obtain status information pertaining
to one of its child processes. Various options permit status information to be obtained for child processes
that have terminated or stopped. If status information is available for two or more child processes, the
order in which their status is reported is unspecified.
The wait() function will suspend execution of the calling process until status information for one of its
terminated child processes is available, or until delivery of a signal whose action is either to execute a
signal-catching function or to terminate the process. If status information is available prior to the call to
wait(), return will be immediate.
The waitpid() function will behave identically to wait(), if the pid argument is (pid_t)−1 and the
options argument is 0. Otherwise, its behaviour will be modified by the values of the pid and options argu-
ments.
The pid argument specifies a set of child processes for which status is requested. The
waitpid() func-
tion will only return the status of a child process from this set:
• If pid is equal to (pid_t)−1, status is requested for any child process. In this respect,
waitpid()
is then equivalent to wait().
• If pid is greater than 0, it specifies the process ID of a single child process for which status is
requested.
• If pid is 0, status is requested for any child process whose process group ID is equal to that of the
calling process.
• If pid is less than (pid_t)−1, status is requested for any child process whose process group ID is
equal to the absolute value of pid.
The options argument is constructed from the bitwise-inclusive OR of zero or more of the following flags,
defined in the header <sys/wait.h> .
WCONTINUED The waitpid() function will report the status of any continued child pro-
cess specified by pid whose status has not been reported since it continued
from a job control stop.
WNOHANG The waitpid() function will not suspend execution of the calling process
if status is not immediately available for one of the child processes specified
by pid.
WUNTRACED The status of any child processes specified by pid that are stopped, and
whose status has not yet been reported since they stopped, will also be
reported to the requesting process.
If the calling process has SA_NOCLDWAIT set or has SIGCHLD set to SIG_IGN, and the process has no
unwaited for children that were transformed into zombie processes, it will block until all of its children ter-
minate, and wait() and waitpid() will fail and set errno to ECHILD.
If wait() or waitpid() return because the status of a child process is available, these functions will
return a value equal to the process ID of the child process. In this case, if the value of the argument
stat_loc is not a null pointer, information will be stored in the location pointed to by stat_loc. If and only if
the status returned is from a terminated child process that returned 0 from main() or passed 0 as the
status argument to _exit() or exit(), the value stored at the location pointed to by stat_loc will be 0.
Regardless of its value, this information may be interpreted using the following macros, which are defined
in <sys/wait.h> and evaluate to integral expressions; the stat_val argument is the integer value
pointed to by stat_loc.
HP-UX Release 11i: December 2000 − 1 − Section 2−−449
___
___