.\" Copyright (c) 1980, 1991 Regents of the University of California.
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. All advertising materials mentioning features or use of this software
.\" must display the following acknowledgement:
.\" This product includes software developed by the University of
.\" California, Berkeley and its contributors.
.\" 4. Neither the name of the University nor the names of its contributors
.\" may be used to endorse or promote products derived from this software
.\" without specific prior written permission.
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" @(#)wait.2 6.5 (Berkeley) 3/10/91
.Nd wait for process termination
.Fd #include <sys/types.h>
.Fd #include <sys/wait.h>
.Fd #include <sys/time.h>
.Fd #include <sys/resource.h>
.Fn waitpid "pid_t wpid" "int *status" "int options"
.Fn wait3 "int *status" "int options" "struct rusage *rusage"
.Fn wait4 "pid_t wpid" "int *status" "int options" "struct rusage *rusage"
function suspends execution of its calling process until
information is available for a terminated child process,
On return from a successful
area contains termination information about the process that exited
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,
The other wait functions are implemented using
parameter specifies the set of child processes for which to wait.
is -1, the call waits for any child process.
the call waits for any child process in the process group of the caller.
is greater than zero, the call waits for the process with process id
is less than -1, the call waits for any process whose process group id
equals the absolute value of
parameter is defined below. The
parameter contains the bitwise OR of any of the following options.
is used to indicate that the call should not block if
there are no processes that wish to report status.
children of the current process that are stopped
.Dv SIGTTIN , SIGTTOU , SIGTSTP ,
is non-zero, a summary of the resources used by the terminated
children is returned (this information is currently not available
option is specified and no processes
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:
True if the process terminated normally by a call to
.It Fn WIFSIGNALED status
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
or if the child process is being traced (see
Depending on the values of those macros, the following macros
produce the remaining status information about the child process:
.It Fn WEXITSTATUS status
is true, evaluates to the low-order 8 bits
of the argument passed to
is true, evaluates to the number of the signal
that caused the termination of the process.
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.
is true, evaluates to the number of the signal
that caused the process to stop.
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
the call may be interrupted or restarted when the signal-catching routine
depending on the options in effect for the signal;
or terminated child process, the process ID of the child
is returned to the calling process. Otherwise, a value of -1
is set to indicate the error.
or terminated child process, the process ID of the child
is returned to the calling process.
If there are no children not previously awaited,
is specified and there are
no stopped or exited children,
If an error is detected or a caught signal aborts the call,
is set to indicate the error.
will fail and return immediately if:
The calling process has no existing unwaited-for
arguments point to an illegal address.
(May not be detected before exit of a child process.)
The call was interrupted by a caught signal,
or the signal did not have the
functions are defined by POSIX;
are not specified by POSIX.
and the ability to restart a pending
call are extensions to the POSIX interface.
function call appeared in