.TH waitpid() "" "" "System Call (libc)"
.PC "Wait for a process to terminate"
.B "#include <sys/types.h>"
.B "#include <sys/wait.h>"
\fBpid_t waitpid(\fIpid\^\fB,\fIstatus\^\fB, \fIflags\^\fB)\fR
\fBpid_t \fIpid\^\fB; int *\fIstatus\^\fB, \fIflags\^\fB;\fR
.PP
.B waitpid()
waits until a given process terminates.
.I pid
identifies the child process whose termination is awaited.
The value of
.I pid
sets the behavior of
.BR waitpid() ,
as follows:
.IP "\fIpid\fR>0"
Wait for the termination of the child process whose identifier is
.IR pid .
.IP "\fIpid\fR=0"
Wait for the termination of any child in the current process group.
.IP "\fIpid\fR=\-1"
Wait for the termination of any child process.
In this mode,
.B waitpid()
behaves the same as the system call
.BR wait() .
.IP "\fIpid\fR<\-1"
Wait for termination of any child in the group given by \fB-\fIpid\fR.
.PP
.I status
points to the place where you want
.B waitpid()
to write the termination status of
.IR pid .
.PP
.I flags
is the logical OR of the following values:
.IP \fBWNOHANG\fR
If
.I pid
has already terminated, write its termination status into
.IR status ;
but if
.I pid
has not yet terminated, do not wait for it to do so.
.IP \fBWUNTRACED\fR
Report the status of every child process of
.I pid
that is stopped, and whose status has not been returned since it stopped.
.PP
By default,
.B waitpid()
returns the process identifier of the chid process whose status is being
reported, or \-1 if something went wrong.
If
.I flags
includes
.BR WNOHANG ,
.B waitpid()
returns zero if no status information is available.
.SH "See Also"
.Xr "libc," libc
.Xr "wait()," wait
.Xr "wait.h" wait.h
.br
\*(PX Standard, \(sc3.2.1
