xref: /minix3/lib/libc/sys/wait.2 (revision 2fe8fb192fe7e8720e3e7a77f928da545e872a6a)
1*2fe8fb19SBen Gras.\"	$NetBSD: wait.2,v 1.27 2010/04/03 15:43:46 jruoho Exp $
2*2fe8fb19SBen Gras.\"
3*2fe8fb19SBen Gras.\" Copyright (c) 1980, 1991, 1993, 1994
4*2fe8fb19SBen Gras.\"	The Regents of the University of California.  All rights reserved.
5*2fe8fb19SBen Gras.\"
6*2fe8fb19SBen Gras.\" Redistribution and use in source and binary forms, with or without
7*2fe8fb19SBen Gras.\" modification, are permitted provided that the following conditions
8*2fe8fb19SBen Gras.\" are met:
9*2fe8fb19SBen Gras.\" 1. Redistributions of source code must retain the above copyright
10*2fe8fb19SBen Gras.\"    notice, this list of conditions and the following disclaimer.
11*2fe8fb19SBen Gras.\" 2. Redistributions in binary form must reproduce the above copyright
12*2fe8fb19SBen Gras.\"    notice, this list of conditions and the following disclaimer in the
13*2fe8fb19SBen Gras.\"    documentation and/or other materials provided with the distribution.
14*2fe8fb19SBen Gras.\" 3. Neither the name of the University nor the names of its contributors
15*2fe8fb19SBen Gras.\"    may be used to endorse or promote products derived from this software
16*2fe8fb19SBen Gras.\"    without specific prior written permission.
17*2fe8fb19SBen Gras.\"
18*2fe8fb19SBen Gras.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19*2fe8fb19SBen Gras.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20*2fe8fb19SBen Gras.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21*2fe8fb19SBen Gras.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22*2fe8fb19SBen Gras.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23*2fe8fb19SBen Gras.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24*2fe8fb19SBen Gras.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25*2fe8fb19SBen Gras.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26*2fe8fb19SBen Gras.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27*2fe8fb19SBen Gras.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28*2fe8fb19SBen Gras.\" SUCH DAMAGE.
29*2fe8fb19SBen Gras.\"
30*2fe8fb19SBen Gras.\"     @(#)wait.2	8.2 (Berkeley) 4/19/94
31*2fe8fb19SBen Gras.\"
32*2fe8fb19SBen Gras.Dd April 3, 2010
33*2fe8fb19SBen Gras.Dt WAIT 2
34*2fe8fb19SBen Gras.Os
35*2fe8fb19SBen Gras.Sh NAME
36*2fe8fb19SBen Gras.Nm wait ,
37*2fe8fb19SBen Gras.Nm waitpid ,
38*2fe8fb19SBen Gras.Nm wait4 ,
39*2fe8fb19SBen Gras.Nm wait3
40*2fe8fb19SBen Gras.Nd wait for process termination
41*2fe8fb19SBen Gras.Sh LIBRARY
42*2fe8fb19SBen Gras.Lb libc
43*2fe8fb19SBen Gras.Sh SYNOPSIS
44*2fe8fb19SBen Gras.In sys/wait.h
45*2fe8fb19SBen Gras.Ft pid_t
46*2fe8fb19SBen Gras.Fn wait "int *status"
47*2fe8fb19SBen Gras.Ft pid_t
48*2fe8fb19SBen Gras.Fn waitpid "pid_t wpid" "int *status" "int options"
49*2fe8fb19SBen Gras.In sys/resource.h
50*2fe8fb19SBen Gras.Ft pid_t
51*2fe8fb19SBen Gras.Fn wait3 "int *status" "int options" "struct rusage *rusage"
52*2fe8fb19SBen Gras.Ft pid_t
53*2fe8fb19SBen Gras.Fn wait4 "pid_t wpid" "int *status" "int options" "struct rusage *rusage"
54*2fe8fb19SBen Gras.Sh DESCRIPTION
55*2fe8fb19SBen GrasThe
56*2fe8fb19SBen Gras.Fn wait
57*2fe8fb19SBen Grasfunction suspends execution of its calling process until
58*2fe8fb19SBen Gras.Fa status
59*2fe8fb19SBen Grasinformation is available for a terminated child process,
60*2fe8fb19SBen Grasor a signal is received.
61*2fe8fb19SBen GrasOn return from a successful
62*2fe8fb19SBen Gras.Fn wait
63*2fe8fb19SBen Grascall,
64*2fe8fb19SBen Grasthe
65*2fe8fb19SBen Gras.Fa status
66*2fe8fb19SBen Grasarea contains termination information about the process that exited
67*2fe8fb19SBen Grasas defined below.
68*2fe8fb19SBen Gras.Pp
69*2fe8fb19SBen GrasThe
70*2fe8fb19SBen Gras.Fn wait4
71*2fe8fb19SBen Grascall provides a more general interface for programs
72*2fe8fb19SBen Grasthat need to wait for certain child processes,
73*2fe8fb19SBen Grasthat need resource utilization statistics accumulated by child processes,
74*2fe8fb19SBen Grasor that require options.
75*2fe8fb19SBen GrasThe other wait functions are implemented using
76*2fe8fb19SBen Gras.Fn wait4 .
77*2fe8fb19SBen Gras.Pp
78*2fe8fb19SBen GrasThe
79*2fe8fb19SBen Gras.Fa wpid
80*2fe8fb19SBen Grasparameter specifies the set of child processes for which to wait.
81*2fe8fb19SBen GrasIf
82*2fe8fb19SBen Gras.Fa wpid
83*2fe8fb19SBen Grasis \-1, the call waits for any child process.
84*2fe8fb19SBen GrasIf
85*2fe8fb19SBen Gras.Fa wpid
86*2fe8fb19SBen Grasis 0,
87*2fe8fb19SBen Grasthe call waits for any child process in the process group of the caller.
88*2fe8fb19SBen GrasIf
89*2fe8fb19SBen Gras.Fa wpid
90*2fe8fb19SBen Grasis greater than zero, the call waits for the process with process id
91*2fe8fb19SBen Gras.Fa wpid .
92*2fe8fb19SBen GrasIf
93*2fe8fb19SBen Gras.Fa wpid
94*2fe8fb19SBen Grasis less than \-1, the call waits for any process whose process group id
95*2fe8fb19SBen Grasequals the absolute value of
96*2fe8fb19SBen Gras.Fa wpid .
97*2fe8fb19SBen Gras.Pp
98*2fe8fb19SBen GrasThe
99*2fe8fb19SBen Gras.Fa status
100*2fe8fb19SBen Grasparameter is defined below.
101*2fe8fb19SBen Gras.Pp
102*2fe8fb19SBen GrasThe
103*2fe8fb19SBen Gras.Fa options
104*2fe8fb19SBen Grasparameter contains the bitwise OR of any of the following options:
105*2fe8fb19SBen Gras.Bl -tag -width WUNTRACED
106*2fe8fb19SBen Gras.It Dv WNOHANG
107*2fe8fb19SBen GrasThis option is used to indicate that the call should not block if
108*2fe8fb19SBen Grasthere are no processes that wish to report status.
109*2fe8fb19SBen Gras.It Dv WUNTRACED
110*2fe8fb19SBen GrasIf this option is set, children of the current process that are stopped
111*2fe8fb19SBen Grasdue to a
112*2fe8fb19SBen Gras.Dv SIGTTIN , SIGTTOU , SIGTSTP ,
113*2fe8fb19SBen Grasor
114*2fe8fb19SBen Gras.Dv SIGSTOP
115*2fe8fb19SBen Grassignal also have their status reported.
116*2fe8fb19SBen Gras.It Dv WALTSIG
117*2fe8fb19SBen GrasIf this option is specified, the call will wait only for processes that
118*2fe8fb19SBen Grasare configured to post a signal other than
119*2fe8fb19SBen Gras.Dv SIGCHLD
120*2fe8fb19SBen Graswhen they exit.
121*2fe8fb19SBen GrasIf
122*2fe8fb19SBen Gras.Dv WALTSIG
123*2fe8fb19SBen Grasis not specified, the call will wait only for processes that
124*2fe8fb19SBen Grasare configured to post
125*2fe8fb19SBen Gras.Dv SIGCHLD .
126*2fe8fb19SBen Gras.It Dv __WCLONE
127*2fe8fb19SBen GrasThis is an alias for
128*2fe8fb19SBen Gras.Dv WALTSIG .
129*2fe8fb19SBen GrasIt is provided for compatibility with the Linux
130*2fe8fb19SBen Gras.Xr clone 2
131*2fe8fb19SBen GrasAPI.
132*2fe8fb19SBen Gras.It Dv WALLSIG
133*2fe8fb19SBen GrasIf this option is specified, the call will wait for all children regardless
134*2fe8fb19SBen Grasof what exit signal they post.
135*2fe8fb19SBen Gras.It Dv __WALL
136*2fe8fb19SBen GrasThis is an alias for
137*2fe8fb19SBen Gras.Dv WALLSIG .
138*2fe8fb19SBen GrasIt is provided for compatibility with the Linux
139*2fe8fb19SBen Gras.Xr clone 2
140*2fe8fb19SBen GrasAPI .
141*2fe8fb19SBen Gras.El
142*2fe8fb19SBen Gras.Pp
143*2fe8fb19SBen GrasIf
144*2fe8fb19SBen Gras.Fa rusage
145*2fe8fb19SBen Grasis non-zero, a summary of the resources used by the terminated
146*2fe8fb19SBen Grasprocess and all its
147*2fe8fb19SBen Graschildren is returned (this information is currently not available
148*2fe8fb19SBen Grasfor stopped processes).
149*2fe8fb19SBen Gras.Pp
150*2fe8fb19SBen GrasWhen the
151*2fe8fb19SBen Gras.Dv WNOHANG
152*2fe8fb19SBen Grasoption is specified and no processes
153*2fe8fb19SBen Graswish to report status,
154*2fe8fb19SBen Gras.Fn wait4
155*2fe8fb19SBen Grasreturns a
156*2fe8fb19SBen Grasprocess id
157*2fe8fb19SBen Grasof 0.
158*2fe8fb19SBen Gras.Pp
159*2fe8fb19SBen GrasThe
160*2fe8fb19SBen Gras.Fn waitpid
161*2fe8fb19SBen Grascall is identical to
162*2fe8fb19SBen Gras.Fn wait4
163*2fe8fb19SBen Graswith an
164*2fe8fb19SBen Gras.Fa rusage
165*2fe8fb19SBen Grasvalue of zero.
166*2fe8fb19SBen GrasThe older
167*2fe8fb19SBen Gras.Fn wait3
168*2fe8fb19SBen Grascall is the same as
169*2fe8fb19SBen Gras.Fn wait4
170*2fe8fb19SBen Graswith a
171*2fe8fb19SBen Gras.Fa wpid
172*2fe8fb19SBen Grasvalue of \-1.
173*2fe8fb19SBen Gras.Pp
174*2fe8fb19SBen GrasThe following macros may be used to test the manner of exit of the process.
175*2fe8fb19SBen GrasNote that these macros expect the
176*2fe8fb19SBen Gras.Fa status
177*2fe8fb19SBen Grasvalue itself, not a pointer to the
178*2fe8fb19SBen Gras.Fa status
179*2fe8fb19SBen Grasvalue.
180*2fe8fb19SBen GrasOne of the first three macros will evaluate to a non-zero (true) value:
181*2fe8fb19SBen Gras.Bl -tag -width Ds
182*2fe8fb19SBen Gras.It Fn WIFEXITED status
183*2fe8fb19SBen GrasTrue if the process terminated normally by a call to
184*2fe8fb19SBen Gras.Xr _exit 2
185*2fe8fb19SBen Grasor
186*2fe8fb19SBen Gras.Xr exit 3 .
187*2fe8fb19SBen Gras.It Fn WIFSIGNALED status
188*2fe8fb19SBen GrasTrue if the process terminated due to receipt of a signal.
189*2fe8fb19SBen Gras.It Fn WIFSTOPPED status
190*2fe8fb19SBen GrasTrue if the process has not terminated, but has stopped and can be restarted.
191*2fe8fb19SBen GrasThis macro can be true only if the wait call specified the
192*2fe8fb19SBen Gras.Dv WUNTRACED
193*2fe8fb19SBen Grasoption
194*2fe8fb19SBen Grasor if the child process is being traced (see
195*2fe8fb19SBen Gras.Xr ptrace 2 ) .
196*2fe8fb19SBen Gras.El
197*2fe8fb19SBen Gras.Pp
198*2fe8fb19SBen GrasDepending on the values of those macros, the following macros
199*2fe8fb19SBen Grasproduce the remaining status information about the child process:
200*2fe8fb19SBen Gras.Bl -tag -width Ds
201*2fe8fb19SBen Gras.It Fn WEXITSTATUS status
202*2fe8fb19SBen GrasIf
203*2fe8fb19SBen Gras.Fn WIFEXITED status
204*2fe8fb19SBen Grasis true, evaluates to the low-order 8 bits
205*2fe8fb19SBen Grasof the argument passed to
206*2fe8fb19SBen Gras.Xr _exit 2
207*2fe8fb19SBen Grasor
208*2fe8fb19SBen Gras.Xr exit 3
209*2fe8fb19SBen Grasby the child.
210*2fe8fb19SBen Gras.It Fn WTERMSIG status
211*2fe8fb19SBen GrasIf
212*2fe8fb19SBen Gras.Fn WIFSIGNALED status
213*2fe8fb19SBen Grasis true, evaluates to the number of the signal
214*2fe8fb19SBen Grasthat caused the termination of the process.
215*2fe8fb19SBen Gras.It Fn WCOREDUMP status
216*2fe8fb19SBen GrasIf
217*2fe8fb19SBen Gras.Fn WIFSIGNALED status
218*2fe8fb19SBen Grasis true, evaluates as true if the termination
219*2fe8fb19SBen Grasof the process was accompanied by the creation of a core file
220*2fe8fb19SBen Grascontaining an image of the process when the signal was received.
221*2fe8fb19SBen Gras.It Fn WSTOPSIG status
222*2fe8fb19SBen GrasIf
223*2fe8fb19SBen Gras.Fn WIFSTOPPED status
224*2fe8fb19SBen Grasis true, evaluates to the number of the signal
225*2fe8fb19SBen Grasthat caused the process to stop.
226*2fe8fb19SBen Gras.El
227*2fe8fb19SBen Gras.Sh NOTES
228*2fe8fb19SBen GrasSee
229*2fe8fb19SBen Gras.Xr sigaction 2
230*2fe8fb19SBen Grasfor a list of termination signals.
231*2fe8fb19SBen GrasA status of 0 indicates normal termination.
232*2fe8fb19SBen Gras.Pp
233*2fe8fb19SBen GrasIf a parent process terminates without
234*2fe8fb19SBen Graswaiting for all of its child processes to terminate,
235*2fe8fb19SBen Grasthe remaining child processes are assigned the parent
236*2fe8fb19SBen Grasprocess 1 ID (the init process ID).
237*2fe8fb19SBen Gras.Pp
238*2fe8fb19SBen GrasIf a signal is caught while any of the
239*2fe8fb19SBen Gras.Fn wait
240*2fe8fb19SBen Grascalls is pending,
241*2fe8fb19SBen Grasthe call may be interrupted or restarted when the signal-catching routine
242*2fe8fb19SBen Grasreturns,
243*2fe8fb19SBen Grasdepending on the options in effect for the signal;
244*2fe8fb19SBen Grassee
245*2fe8fb19SBen Gras.Xr intro 2 ,
246*2fe8fb19SBen GrasSystem call restart.
247*2fe8fb19SBen Gras.Sh RETURN VALUES
248*2fe8fb19SBen GrasIf
249*2fe8fb19SBen Gras.Fn wait
250*2fe8fb19SBen Grasreturns due to a stopped
251*2fe8fb19SBen Grasor terminated child process, the process ID of the child
252*2fe8fb19SBen Grasis returned to the calling process.
253*2fe8fb19SBen GrasOtherwise, a value of \-1 is returned and
254*2fe8fb19SBen Gras.Va errno
255*2fe8fb19SBen Grasis set to indicate the error.
256*2fe8fb19SBen Gras.Pp
257*2fe8fb19SBen GrasIf
258*2fe8fb19SBen Gras.Fn wait4 ,
259*2fe8fb19SBen Gras.Fn wait3
260*2fe8fb19SBen Grasor
261*2fe8fb19SBen Gras.Fn waitpid
262*2fe8fb19SBen Grasreturns due to a stopped
263*2fe8fb19SBen Grasor terminated child process, the process ID of the child
264*2fe8fb19SBen Grasis returned to the calling process.
265*2fe8fb19SBen GrasIf there are no children not previously awaited,
266*2fe8fb19SBen Gras\-1 is returned with
267*2fe8fb19SBen Gras.Va errno
268*2fe8fb19SBen Grasset to
269*2fe8fb19SBen Gras.Bq Er ECHILD .
270*2fe8fb19SBen GrasOtherwise, if
271*2fe8fb19SBen Gras.Dv WNOHANG
272*2fe8fb19SBen Grasis specified and there are
273*2fe8fb19SBen Grasno stopped or exited children, 0 is returned.
274*2fe8fb19SBen GrasIf an error is detected or a caught signal aborts the call,
275*2fe8fb19SBen Grasa value of \-1 is returned and
276*2fe8fb19SBen Gras.Va errno
277*2fe8fb19SBen Grasis set to indicate the error.
278*2fe8fb19SBen Gras.Sh ERRORS
279*2fe8fb19SBen Gras.Fn wait
280*2fe8fb19SBen Graswill fail and return immediately if:
281*2fe8fb19SBen Gras.Bl -tag -width Er
282*2fe8fb19SBen Gras.It Bq Er ECHILD
283*2fe8fb19SBen GrasThe calling process has no existing unwaited-for child processes.
284*2fe8fb19SBen Gras.It Bq Er EFAULT
285*2fe8fb19SBen GrasThe
286*2fe8fb19SBen Gras.Fa status
287*2fe8fb19SBen Grasor
288*2fe8fb19SBen Gras.Fa rusage
289*2fe8fb19SBen Grasarguments point to an illegal address.
290*2fe8fb19SBen Gras(May not be detected before exit of a child process.)
291*2fe8fb19SBen Gras.It Bq Er EINTR
292*2fe8fb19SBen GrasThe call was interrupted by a caught signal,
293*2fe8fb19SBen Grasor the signal did not have the
294*2fe8fb19SBen Gras.Dv SA_RESTART
295*2fe8fb19SBen Grasflag set.
296*2fe8fb19SBen Gras.El
297*2fe8fb19SBen Gras.Pp
298*2fe8fb19SBen GrasIn addition,
299*2fe8fb19SBen Gras.Fn wait3 ,
300*2fe8fb19SBen Gras.Fn wait4 ,
301*2fe8fb19SBen Grasand
302*2fe8fb19SBen Gras.Fn waitpid
303*2fe8fb19SBen Graswill fail and return immediately if:
304*2fe8fb19SBen Gras.Bl -tag -width Er
305*2fe8fb19SBen Gras.It Bq Er EINVAL
306*2fe8fb19SBen GrasAn invalid value was specified for
307*2fe8fb19SBen Gras.Fa options .
308*2fe8fb19SBen Gras.El
309*2fe8fb19SBen Gras.Sh SEE ALSO
310*2fe8fb19SBen Gras.Xr _exit 2 ,
311*2fe8fb19SBen Gras.Xr sigaction 2
312*2fe8fb19SBen Gras.Sh STANDARDS
313*2fe8fb19SBen GrasThe
314*2fe8fb19SBen Gras.Fn wait
315*2fe8fb19SBen Grasand
316*2fe8fb19SBen Gras.Fn waitpid
317*2fe8fb19SBen Grasfunctions conform to
318*2fe8fb19SBen Gras.St -p1003.1-90 ;
319*2fe8fb19SBen Grasthe
320*2fe8fb19SBen Gras.Fn wait3
321*2fe8fb19SBen Grasfunction conforms to
322*2fe8fb19SBen Gras.St -xpg4 ;
323*2fe8fb19SBen Gras.Fn wait4
324*2fe8fb19SBen Grasis an extension.
325*2fe8fb19SBen GrasThe
326*2fe8fb19SBen Gras.Fn WCOREDUMP
327*2fe8fb19SBen Grasmacro
328*2fe8fb19SBen Grasand the ability to restart a pending
329*2fe8fb19SBen Gras.Fn wait
330*2fe8fb19SBen Grascall are extensions to the POSIX interface.
331*2fe8fb19SBen Gras.Sh HISTORY
332*2fe8fb19SBen GrasA
333*2fe8fb19SBen Gras.Fn wait
334*2fe8fb19SBen Grasfunction call appeared in
335*2fe8fb19SBen Gras.At v2 .
336