HP-UX Reference (11i v2 03/08) - 2 System Calls (vol 5)

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);
DESCRIPTION
The wait() and waitpid() functions shall 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
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 shall suspend execution of the calling thread until status information for one of the
terminated 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 shall
return the process status at the time of the target process termination. If status information is available
prior to the call to wait(), return shall be immediate.
The
waitpid() function shall be equivalent to wait() if the pid argument is (pid_t) 1 and the
options argument is 0. Otherwise, its behavior shall be 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
shall 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,
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 shall report 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 shall 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, pro-
vided 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, shall also be reported to the
requesting process.
HP-UX EXTENSION: If and only if this flag is set,
waitpid() or wait3()
returns information on child or attached processes that are stopped but not traced
(with ptrace()) because they received a SIGTTIN, SIGTTOU, SIGTSTP or
SIGSTOP signal, and whose status has not yet been reported. Regardless of this
flag, status is returned for child or attached processes that have terminated or are
Section 2480 Hewlett-Packard Company 1 HP-UX 11i Version 2: August 2003