The wait function suspends execution of its calling process until status information is available for a terminated child process, or a signal is received. On return from a successful wait call, the status area contains termination information about the process that exited as defined below.
The wait4 system call provides a more general interface for programs that need to wait for certain child processes, that need resource utilization statistics accumulated by child processes, or that require options. The other wait functions are implemented using wait4.
The wpid argument specifies the set of child processes for which to wait. If wpid is -1, the call waits for any child process. If wpid is 0, the call waits for any child process in the process group of the caller. If wpid is greater than zero, the call waits for the process with process id wpid. If wpid is less than -1, the call waits for any process whose process group id equals the absolute value of wpid.
The status argument is defined below. The options argument contains the bitwise OR of any of the following options. The WCONTINUED option indicates that children of the current process that have continued from a job control stop, by receiving a SIGCONT signal, should also have their status reported. The WNOHANG option is used to indicate that the call should not block if there are no processes that wish to report status. If the WUNTRACED option is set, children of the current process that are stopped due to a SIGTTIN, SIGTTOU, SIGTSTP, or SIGSTOP signal also have their status reported.
If rusage is non-zero, 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 wish to report status, wait4 returns a process id of 0.
The waitpid function is identical to wait4 with an rusage value of zero. The older wait3 call is the same as wait4 with a wpid value of -1.
The following macros may be used to test the manner of exit of the process. One of the first three macros will evaluate to a non-zero (true) value: