int wait(statusp) union wait *statusp;
int wait((union wait *)0)
#include <sys/time.h> #include <sys/resource.h>
int wait3(statusp, options, rusage) union wait *statusp; int options; struct rusage *rusage;
int wait4(pid, statusp, options, rusage) int pid; union wait *statusp; int options; struct rusage *rusage;
WIFSTOPPED(status) union wait status;
WIFSIGNALED(status) union wait status;
WIFEXITED(status) union wait status;
This is the BSD specification for wait. For the POSIX specification, see wait(2P).
wait() delays its caller until a signal is received or one of its child processes terminates or stops due to tracing. If any child has died or stopped due to tracing and this has not been reported using wait, return is immediate, returning the process ID and exit status of one of those children. If that child had died, it is discarded. If there are no children, return is immediate with the value -1 returned. If there are only running or stopped but reported children, the calling process is blocked.
If status is not a NULL pointer, then on return from a successful wait() call the status of the child process whose process ID is the return value of wait() is stored in the wait() union pointed to by status. The w_status member of that union is an int; it indicates the cause of termination and other information about the terminated process in the following manner:
Other members of the wait() union can be used to extract this information more conveniently:
The other members of the wait() union merely provide an alternate way of analyzing the status. The value stored in the w_status field is compatible with the values stored by other versions of the UNIX system, and an argument of type int * may be provided instead of an argument of type union wait * for compatibility with those versions.
wait3() is an alternate interface that allows both non-blocking status collection and the collection of the status of children stopped by any means. The status parameter is defined as above. The options parameter is used to indicate the call should not block if there are no processes that have status to report (WNOHANG), and/or that children of the current process that are stopped due to a SIGTTIN, SIGTTOU, SIGTSTP, or SIGSTOP signal are eligible to have their status reported as well (WUNTRACED). A terminated child is discarded after it reports status, and a stopped process will not report its status more than once. If rusage is not a NULL pointer, a summary of the resources used by the terminated process and all its children is returned. (This information is currently not available for stopped processes.)
When the WNOHANG option is specified and no processes have status to report, wait3() returns 0. The WNOHANG and WUNTRACED options may be combined by ORing the two values.
wait4() is another alternate interface. With a pid argument of 0, it is equivalent to wait3. If pid has a nonzero value, then wait4() returns status only for the indicated process ID, but not for any other child processes.
WIFSTOPPED, WIFSIGNALED, WIFEXITED, are macros that take an argument status, of type `union wait', as returned by wait, wait2, wait3, or wait4. WIFSTOPPED evaluates to true (1) when the process for which the wait() call was made is stopped, or to false (0) otherwise. WIFSIGNALED evaluates to true when the process was terminated with a signal. WIFEXITED evaluates to true when the process exited by using an exit.2 call.
wait, wait3, and wait4() are automatically restarted when a process receives a signal while awaiting termination of a child process, unless the SV_INTERRUPT bit is set in the flags for that signal.
wait3() and wait4() return 0 if WNOHANG is specified and there are no stopped or exited children, and return the process ID of the child process if they return due to a stopped or terminated child process. Otherwise, they return a value of -1 and set errno to indicate the error.
wait, wait3, and wait4 will terminate prematurely, return -1, and set errno to EINTR upon the arrival of a signal whose SV_INTERRUPT bit in its flags field is set (see sigvec.2 and siginterrupt.3
wait( (union wait *) 0)
Otherwise the compiler might complain.
Created by unroff & hp-tools. © by Hans-Peter Bischof. All Rights Reserved (1997).
Last modified 21/April/97