Add copyright
[unix-history] / usr / src / lib / libc / sys / wait.2
CommitLineData
775a8be6
KM
1.\" Copyright (c) 1980 Regents of the University of California.
2.\" All rights reserved. The Berkeley software License Agreement
3.\" specifies the terms and conditions for redistribution.
4.\"
60384211 5.\" @(#)wait.2 6.1 (Berkeley) %G%
775a8be6 6.\"
60384211 7.TH WAIT 2 ""
775a8be6
KM
8.UC 4
9.SH NAME
28494293 10wait, wait3 \- wait for process to terminate
775a8be6 11.SH SYNOPSIS
28494293 12.ft B
775a8be6 13.nf
28494293
KM
14#include <sys/wait.h>
15.PP
16.ft B
17pid = wait(status)
18int pid;
19union wait *status;
20.PP
21.ft B
22pid = wait(0)
23int pid;
24.PP
25.ft B
26#include <sys/time.h>
27#include <sys/resource.h>
775a8be6 28.PP
28494293
KM
29.ft B
30pid = wait3(status, options, rusage)
31int pid;
32union wait *status;
33int options;
34struct rusage *rusage;
35.fi
775a8be6
KM
36.SH DESCRIPTION
37.I Wait
38causes its caller to delay until a signal is received or
39one of its child
40processes terminates.
41If any child has died since the last
28494293
KM
42.IR wait ,
43return is immediate, returning the process id and
44exit status of one of the terminated
45children.
46If there are no children, return is immediate with
47the value \-1 returned.
775a8be6 48.PP
28494293
KM
49On return from a successful
50.I wait
51call,
52.I status
53is nonzero, and the high byte of
54.I status
55contains the low byte of the argument to
775a8be6 56.I exit
28494293
KM
57supplied by the child process;
58the low byte of
59.I status
60contains the termination status of the process.
61A more precise definition of the
62.I status
63word is given in
64.RI < sys/wait.h >.
65.PP
66.I Wait3
67provides an alternate interface for programs
68which must not block when collecting the status
69of child processes. The
70.I status
71parameter is defined as above. The
72.I options
73parameter is used to indicate the call should not block if
74there are no processes which wish to report status (WNOHANG),
60384211
KM
75and/or that children of the current process which are stopped
76due to a SIGTTIN, SIGTTOU, SIGTSTP, or SIGSTOP signal should also have
28494293
KM
77their status reported (WUNTRACED). If
78.I rusage
79is non-zero, a summary of the resources used by the terminated
80process and all its
81children is returned (this information is currently not available
82for stopped processes).
83.PP
84When the WNOHANG option is specified and no processes
85wish to report status,
86.I wait3
87returns a
88.I pid
89of 0. The WNOHANG and WUNTRACED options may be combined by
90.IR or 'ing
91the two values.
92.SH NOTES
775a8be6 93See
28494293 94.IR sigvec (2)
775a8be6
KM
95for a list of termination statuses (signals);
960 status indicates normal termination.
97A special status (0177) is returned for a stopped process
28494293
KM
98which has not terminated and can be restarted;
99see
775a8be6
KM
100.IR ptrace (2).
101If the 0200 bit of the termination status
102is set,
103a core image of the process was produced
104by the system.
105.PP
106If the parent process terminates without
107waiting on its children,
108the initialization process
109(process ID = 1)
110inherits the children.
111.PP
28494293
KM
112.I Wait
113and
114.I wait3
115are automatically restarted when a process receives a
116signal while awaiting termination of a child process.
117.SH "RETURN VALUE
118If \fIwait\fP returns due to a stopped
119or terminated child process, the process ID of the child
120is returned to the calling process. Otherwise, a value of \-1
121is returned and \fIerrno\fP is set to indicate the error.
775a8be6 122.PP
28494293
KM
123.I Wait3
124returns \-1 if there are no children not previously waited
125for; 0 is returned if WNOHANG is specified and there are
126no stopped or exited children.
127.SH ERRORS
128.I Wait
129will fail and return immediately if one or more of the following
130are true:
131.TP 15
132[ECHILD]
133The calling process has no existing unwaited-for
134child processes.
135.TP 15
136[EFAULT]
137The \fIstatus\fP or \fIrusage\fP arguments point to an illegal address.
138.SH "SEE ALSO"
139exit(2)