1 .\" $NetBSD: wait.2,v 1.6 1995/02/27 12:39:37 cgd Exp $
3 .\" Copyright (c) 1980, 1991, 1993, 1994
4 .\" The Regents of the University of California. All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
14 .\" 3. All advertising materials mentioning features or use of this software
15 .\" must display the following acknowledgement:
16 .\" This product includes software developed by the University of
17 .\" California, Berkeley and its contributors.
18 .\" 4. Neither the name of the University nor the names of its contributors
19 .\" may be used to endorse or promote products derived from this software
20 .\" without specific prior written permission.
22 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 .\" @(#)wait.2 8.2 (Berkeley) 4/19/94
44 .Nd wait for process termination
46 .Fd #include <sys/wait.h>
55 .Fa "struct rusage *rusage"
62 .Fa "struct rusage *rusage"
73 function suspends execution of its calling process until
75 information is available for a terminated child process,
76 or a signal is received.
77 On return from a successful
82 area contains termination information about the process that exited
87 call provides a more general interface for programs
88 that need to wait for certain child processes,
89 that need resource utilization statistics accumulated by child processes,
90 or that require options.
91 The other wait functions are implemented using
96 parameter specifies the set of child processes for which to wait.
99 is -1, the call waits for any child process.
103 the call waits for any child process in the process group of the caller.
106 is greater than zero, the call waits for the process with process id
110 is less than -1, the call waits for any process whose process group id
111 equals the absolute value of
116 parameter is defined below. The
118 parameter contains the bitwise OR of any of the following options.
122 is used to indicate that the call should not block if
123 there are no processes that wish to report status.
127 children of the current process that are stopped
129 .Dv SIGTTIN , SIGTTOU , SIGTSTP ,
133 their status reported.
137 is non-zero, a summary of the resources used by the terminated
139 children is returned (this information is currently not available
140 for stopped processes).
144 option is specified and no processes
145 wish to report status,
166 The following macros may be used to test the manner of exit of the process.
167 One of the first three macros will evaluate to a non-zero (true) value:
169 .It Fn WIFEXITED status
170 True if the process terminated normally by a call to
174 .It Fn WIFSIGNALED status
175 True if the process terminated due to receipt of a signal.
176 .It Fn WIFSTOPPED status
177 True if the process has not terminated, but has stopped and can be restarted.
178 This macro can be true only if the wait call specified the
181 or if the child process is being traced (see
185 Depending on the values of those macros, the following macros
186 produce the remaining status information about the child process:
188 .It Fn WEXITSTATUS status
191 is true, evaluates to the low-order 8 bits
192 of the argument passed to
197 .It Fn WTERMSIG status
199 .Fn WIFSIGNALED status
200 is true, evaluates to the number of the signal
201 that caused the termination of the process.
202 .It Fn WCOREDUMP status
204 .Fn WIFSIGNALED status
205 is true, evaluates as true if the termination
206 of the process was accompanied by the creation of a core file
207 containing an image of the process when the signal was received.
208 .It Fn WSTOPSIG status
210 .Fn WIFSTOPPED status
211 is true, evaluates to the number of the signal
212 that caused the process to stop.
217 for a list of termination signals.
218 A status of 0 indicates normal termination.
220 If a parent process terminates without
221 waiting for all of its child processes to terminate,
222 the remaining child processes are assigned the parent
223 process 1 ID (the init process ID).
225 If a signal is caught while any of the
228 the call may be interrupted or restarted when the signal-catching routine
230 depending on the options in effect for the signal;
237 returns due to a stopped
238 or terminated child process, the process ID of the child
239 is returned to the calling process. Otherwise, a value of -1
242 is set to indicate the error.
249 returns due to a stopped
250 or terminated child process, the process ID of the child
251 is returned to the calling process.
252 If there are no children not previously awaited,
259 is specified and there are
260 no stopped or exited children,
262 If an error is detected or a caught signal aborts the call,
266 is set to indicate the error.
270 system call will fail and return immediately if:
274 The calling process has no existing unwaited-for child processes.
281 argument points to an illegal address
282 (may not be detected before the exit of a child process).
285 Invalid or undefined flags are passed in the
294 calls will fail and return immediately if:
298 The process specified by
300 does not exist or is not a child of the calling process,
301 or the process group specified by
303 does not exist or does not have any member process
304 that is a child of the calling process.
309 call will fail and return immediately if:
313 The options argument is not valid.
316 Any of these calls will fail and return immediately if:
320 The call is interrupted by a caught signal
321 or the signal does not have the
330 functions are defined by POSIX;
334 are not specified by POSIX.
338 and the ability to restart a pending
340 call are extensions to the POSIX interface.
342 .Fd #include <sys/types.h>
343 .Fd #include <sys/wait.h>
355 function call appeared in