NAME
wait, waitpid, wait3, wait4 - wait for process to terminate

SYNOPSIS
#include <sys/wait.h>

pid = wait(status)
int pid;
union wait *status;

pid = wait(0)
int pid;

#include <sys/time.h>
#include <sys/resource.h>

pid = waitpid(wpid, status, options)
int pid, wpid;
union wait *status;
int options;

pid = wait3(status, options, rusage)
int pid;
union wait *status;
int options;
struct rusage *rusage; or struct rusage_dev *rusage;

pid = wait4(wpid, status, options, rusage)
int pid, wpid;
union wait *status;
int options;
struct rusage *rusage; or struct rusage_dev *rusage;

DESCRIPTION
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 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 value -1 returned.

On return from a successful wait call, status is nonzero, and the
high byte of status contains the low byte of the argument to exit
supplied by the child process; the low byte of status contains the
termination status of the process. A more precise definition of
the status word is given in <sys/wait.h>.

Wait4 provides a more general interface for programs that need to
wait for certain child processes, that need resource utilization
statistics accummulated by child processes, or that require
options. The other wait functions are implemented using wait4.

The wpid parameter 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 parameter is defined below. The options parameter
contains the bitwise OR of any of the following options. 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 call 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.

Under Mach: If the WLOGINDEV bit is or’ed into options then wait4
returns an augmented rusage structure upon process termination.
This rusage_dev structure contains all the standard rusage
summaries as well as an additional field which reports the device
number of the controlling terminal associated with the initial
shell process of a login session. If the exiting process was not a
login shell process, the reported device number is the constant
RUSAGE_NODEV. This option is used by init(8) to clean up login
state for a terminal (such as in utmp(5)) after login shells
invoked by network servers and window managers (but which init
typically inherits) finally exit so that this clean up function
need not be duplicated in all such applications.

NOTES
See sigvec(2) for a list of termination statuses (signals); 0
status indicates normal termination. A special status (0177) is
returned for a stopped process that has not terminated and can be
restarted; see ptrace(2)*. If the 0200 bit of the termination
status is set, a core image of the process was produced by the
system.

If the parent process terminates without waiting on its children,
the initialization process (process ID = 1) inherits the children.

Wait and wait3 are automatically restarted when a process receives
a signal while awaiting termination of a child process.

RETURN VALUE
If wait 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 errno is set to indicate
the error.

Wait3 returns -1 if there are no children not previously waited
for; 0 is returned if WNOHANG is specified and there are no
stopped or exited children.

ERRORS
Wait will fail and return immediately if one or more of the
following are true:

[ECHILD] The calling process has no existing unwaited-for
child processes.

[EFAULT] The status or rusage arguments point to an illegal
address.

SEE ALSO
exit(2)

__________
* Not currently supported under MachTen Personal Unix