4.1cBSD/usr/man/man2/wait.2

Compare this file to the similar file:
Show the results in this format:

.TH WAIT 2 2/12/83
.SH NAME
wait \- wait for process to terminate
.SH SYNOPSIS
.ft B
.nf
#include <wait.h>

pid = wait(&status)
int pid;
union wait status;
.PP
.ft B
pid = wait(0)
int pid;
.fi
.SH DESCRIPTION
.I Wait
causes its caller to delay until a signal is received or
one of its child
processes terminates.
If any child has died since the last
.I wait,
return is immediate, returning the process id and
exit status of one of the terminated
children.
If there are no children, return is immediate with
the a value of \-1 returned.
.PP
If status
is nonzero, the high byte of the word pointed to
receives the low byte of the
argument of
.I exit
when the child terminated.
The low byte
receives the termination status
of the process.
A more precise definition of the \fIstatus\fP word
is available as defined in <\fIwait.h\fP>.
.PP
See
.IR signal (2)
for a list of termination statuses (signals);
0 status indicates normal termination.
A special status (0177) is returned for a stopped process
which has not terminated and can be restarted.
See
.IR ptrace (2).
If the 0200 bit of the termination status
is set,
a core image of the process was produced
by the system.
.PP
If the parent process terminates without
waiting on its children,
the initialization process
(process ID = 1)
inherits the children.
.SH "RETURN VALUE
If \fIwait\fP returns due to the receipt of a signal, a value
of \-1 is returned to the calling process and \fIerrno\fP
is set to EINTRY.  If \fIwait\fP returns due to a stopped
or terminated child process, the process ID of the child
is returned to the calling process.  Otherwise, a value of \-1
is returned and \fIerrno\fP is set to indicate the error.
.SH ERRORS
.I Wait
will fail and return immediately if one or more of the following
are true:
.TP 15
[ECHLID]
The calling process has no existing unwaited-for
child processes.
.TP 15
[EFAULT]
The \fIstatus\fP argument points to an illegal address.
.SH "SEE ALSO"
exit(2), wait3(2)