wait.2 (2010 09)
w
wait(2) wait(2)
NAME
wait(), waitpid() - wait for child process to stop or terminate
SYNOPSIS
#include <sys/types.h>
#include <sys/wait.h>
pid_t wait(
int *stat_loc
);
pid_t waitpid(
pid_t pid,
int *stat_loc ,
int options
);
DESCIPTION
The wait() and waitpid() functions obtain status information pertaining to one of the caller’s child
processes. Various options permit status information to be obtained for child processes that have ter-
minated 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 suspends execution of the calling thread until status information for one of the ter-
minated child processes of the calling process is available, or until delivery of a signal whose action is
either to execute a signal-catching function or to terminate the process. If more than one thread is
suspended in wait() or waitpid() awaiting termination of the same process, exactly one thread
returns the process status at the time of the target process termination. If status information is available
prior to the call to wait(), return is immediate.
The
waitpid() function is equivalent to wait() if the pid argument is (pid_t)-1 and the options
argument is 0. Otherwise, its behavior is modified by the values of the pid and options arguments.
Note that if the parent process terminates without waiting for its child processes to terminate, these
processes are adopted by and recognize the initialization process as their parent.
The pid argument specifies the child processes for which status is requested. The
waitpid() function
only returns 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,
wait-
pid() is 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 stat_loc argument is the address where status of the specified child processes is placed.
The options argument is constructed from the bitwise-inclusive OR of zero or more of the following flags
defined in the
<sys/wait.h> header file.
WCONTINUED The waitpid() function reports the status of any continued child process
specified by pid whose status has not been reported since it continued from a job
control stop.
WNOHANG The waitpid() function does not suspend execution of the calling thread if status
is not immediately available for one of the child processes specified by pid .
WNOWAIT HP-UX EXTENSION: Keep the process whose status is returned in stat_loc in a
waitable state. The process may be waited for again with identical results, provided
the state of the process doesn’t change in the interim.
WUNTRACED The status of any child processes specified by pid that are stopped, and whose
status has not yet been reported since they stopped, is also reported to the request-
ing process.
HP-UX 11i Version 3: September 2010 − 1 − Hewlett-Packard Company 1