|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.|
|is used to indicate that the call should not block when there are no processes wishing to report status.|
|indicates that children of the current process which are stopped due to a SIGTTIN, SIGTTOU, SIGTSTP, or SIGSTOP signal shall have their status reported.|
|is an alias for WUNTRACED.|
|allows waiting for processes which have trapped or reached a breakpoint.|
indicates that the caller is wants to receive status reports from
This flag is implicitly set for the functions
For the waitid and wait6 functions, the flag has to be explicitly included in the options, if status reports from terminated processes are expected.
|keeps the process whose status is returned in a waitable state. The process may be waited for again after this call completes.|
For the waitid and wait6 functions, at least one of the options WEXITED, WUNTRACED, WSTOPPED, WTRAPPED, or WCONTINUED must be specified. Otherwise there will be no events for the call to report. To avoid hanging indefinitely in such a case these functions return -1 with errno set to EINVAL.
If rusage is non-NULL, a summary of the resources used by the terminated process and all its children is returned.
If wrusage argument is non-NULL, a resource usage statistics from both its own child process as well as from its grand children is returned.
If infop is non-NULL, it must point to a siginfo_t structure which is filled on return such that the si_signo field is always SIGCHLD and the field si_pid if be non-zero, if there is a status change to report. If there are no status changes to report and WNOHANG is applied, both of these fields are returned zero. When using the waitid function with the WNOHANG option set, checking these fields is the only way to know whether there were any status changes to report, because the return value from waitid is be zero as it is for any successful return from waitid.
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 wait6 call, with the bits WEXITED and WTRAPPED set in the options and with infop set to NULL, is similar to wait4.
The following macros may be used to test the manner of exit of the process. One of the first four macros will evaluate to a non-zero (true) value:
|True if the process has not terminated, and has continued after a job control stop. This macro can be true only if the wait call specified the WCONTINUED option).|
|True if the process terminated normally by a call to _exit(2) or exit(3).|
|True if the process terminated due to receipt of a signal.|
|True if the process has not terminated, but has stopped and can be restarted. This macro can be true only if the wait call specified the WUNTRACED option or if the child process is being traced (see ptrace(2)).|
Depending on the values of those macros, the following macros produce the remaining status information about the child process:
|If WIFEXITED status is true, evaluates to the low-order 8 bits of the argument passed to _exit(2) or exit(3) by the child.|
|If WIFSIGNALED status is true, evaluates to the number of the signal that caused the termination of the process.|
|If WIFSIGNALED status is true, evaluates as true if the termination of the process was accompanied by the creation of a core file containing an image of the process when the signal was received.|
|If WIFSTOPPED status is true, evaluates to the number of the signal that caused the process to stop.|
See sigaction(2) for a list of termination signals. A status of 0 indicates normal termination.
If a parent process terminates without waiting for all of its child processes to terminate, the remaining child processes are assigned the parent process 1 ID (the init process ID).
If a signal is caught while any of the wait calls are pending, the call may be interrupted or restarted when the signal-catching routine returns, depending on the options in effect for the signal; see discussion of SA_RESTART in sigaction(2).
The implementation queues one SIGCHLD signal for each child process whose status has changed, if wait returns because the status of a child process is available, the pending SIGCHLD signal associated with the process ID of the child process will be discarded. Any other pending SIGCHLD signals remain pending.
If SIGCHLD is blocked, wait returns because the status of a child process is available, the pending SIGCHLD signal will be cleared unless another status of the child process is available.
If wait returns due to a stopped, continued, or terminated child process, the process ID of the child is returned to the calling process. Otherwise, a value of -1 is returned and errno is set to indicate the error.
If wait6, wait4, wait3, or waitpid returns due to a stopped, continued, or terminated child process, the process ID of the child is returned to the calling process. If there are no children not previously awaited, -1 is returned with errno set to ECHILD. Otherwise, if WNOHANG is specified and there are no stopped, continued or exited children, 0 is returned. If an error is detected or a caught signal aborts the call, a value of -1 is returned and errno is set to indicate the error.
If waitid returns because one or more processes have a state change to report, 0 is returned. To indicate an error, -1 will be returned and errno set to an appropriate value. If WNOHANG was used, 0 can be returned indicating no error, but no processes may have changed state either, if si_signo and/or si_pid are zero.
The wait function will fail and return immediately if:
[ECHILD] The calling process has no existing unwaited-for child processes. [ECHILD] No status from the terminated child process is available because the calling process has asked the system to discard such status by ignoring the signal SIGCHLD or setting the flag SA_NOCLDWAIT for that signal. [EFAULT] The status or rusage argument points to an illegal address. (May not be detected before exit of a child process.) [EINTR] The call was interrupted by a caught signal, or the signal did not have the SA_RESTART flag set. [EINVAL] An invalid value was specified for options, or idtype and id do not specify a valid set of processes.
The wait, waitpid, and waitid functions are defined by POSIX; wait6, wait4, and wait3 are not specified by POSIX. The WCOREDUMP macro is an extension to the POSIX interface.
The ability to use the WNOWAIT flag with waitpid is an extension; POSIX only permits this flag with waitid.
POSIX requires waitid to return the full 32 bits passed to _exit(2); this implementation only returns 8 bits like in the other calls.
The wait function appeared in AT&T v6 .