1 .\" Copyright (c) 1980, 1991, 1993, 1994
2 .\" The Regents of the University of California. All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\" notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\" notice, this list of conditions and the following disclaimer in the
11 .\" documentation and/or other materials provided with the distribution.
12 .\" 3. All advertising materials mentioning features or use of this software
13 .\" must display the following acknowledgement:
14 .\" This product includes software developed by the University of
15 .\" California, Berkeley and its contributors.
16 .\" 4. Neither the name of the University nor the names of its contributors
17 .\" may be used to endorse or promote products derived from this software
18 .\" without specific prior written permission.
20 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 .\" @(#)wait.2 8.2 (Berkeley) 4/19/94
33 .\" $FreeBSD: src/lib/libc/sys/wait.2,v 1.6.2.6 2001/12/14 18:34:02 ru Exp $
34 .\" $DragonFly: src/lib/libc/sys/wait.2,v 1.3 2006/02/17 19:35:06 swildner Exp $
44 .Nd wait for process termination
51 .Fn wait "int *status"
55 .Fn waitpid "pid_t wpid" "int *status" "int options"
57 .Fn wait3 "int *status" "int options" "struct rusage *rusage"
59 .Fn wait4 "pid_t wpid" "int *status" "int options" "struct rusage *rusage"
63 function suspends execution of its calling process until
65 information is available for a terminated child process,
66 or a signal is received.
67 On return from a successful
72 area contains termination information about the process that exited
77 call provides a more general interface for programs
78 that need to wait for certain child processes,
79 that need resource utilization statistics accumulated by child processes,
80 or that require options.
81 The other wait functions are implemented using
86 parameter specifies the set of child processes for which to wait.
89 is -1, the call waits for any child process.
93 the call waits for any child process in the process group of the caller.
96 is greater than zero, the call waits for the process with process id
100 is less than -1, the call waits for any process whose process group id
101 equals the absolute value of
106 parameter is defined below. The
108 parameter contains the bitwise OR of any of the following options.
112 is used to indicate that the call should not block if
113 there are no processes that wish to report status.
117 children of the current process that are stopped
119 .Dv SIGTTIN , SIGTTOU , SIGTSTP ,
123 their status reported.
127 is non-zero, a summary of the resources used by the terminated
129 children is returned (this information is currently not available
130 for stopped processes).
134 option is specified and no processes
135 wish to report status,
156 The following macros may be used to test the manner of exit of the process.
157 One of the first three macros will evaluate to a non-zero (true) value:
159 .It Fn WIFEXITED status
160 True if the process terminated normally by a call to
164 .It Fn WIFSIGNALED status
165 True if the process terminated due to receipt of a signal.
166 .It Fn WIFSTOPPED status
167 True if the process has not terminated, but has stopped and can be restarted.
168 This macro can be true only if the wait call specified the
171 or if the child process is being traced (see
175 Depending on the values of those macros, the following macros
176 produce the remaining status information about the child process:
178 .It Fn WEXITSTATUS status
181 is true, evaluates to the low-order 8 bits
182 of the argument passed to
187 .It Fn WTERMSIG status
189 .Fn WIFSIGNALED status
190 is true, evaluates to the number of the signal
191 that caused the termination of the process.
192 .It Fn WCOREDUMP status
194 .Fn WIFSIGNALED status
195 is true, evaluates as true if the termination
196 of the process was accompanied by the creation of a core file
197 containing an image of the process when the signal was received.
198 .It Fn WSTOPSIG status
200 .Fn WIFSTOPPED status
201 is true, evaluates to the number of the signal
202 that caused the process to stop.
207 for a list of termination signals.
208 A status of 0 indicates normal termination.
210 If a parent process terminates without
211 waiting for all of its child processes to terminate,
212 the remaining child processes are assigned the parent
213 process 1 ID (the init process ID).
215 If a signal is caught while any of the
218 the call may be interrupted or restarted when the signal-catching routine
220 depending on the options in effect for the signal;
227 returns due to a stopped
228 or terminated child process, the process ID of the child
229 is returned to the calling process. Otherwise, a value of -1
232 is set to indicate the error.
239 returns due to a stopped
240 or terminated child process, the process ID of the child
241 is returned to the calling process.
242 If there are no children not previously awaited,
249 is specified and there are
250 no stopped or exited children,
252 If an error is detected or a caught signal aborts the call,
256 is set to indicate the error.
259 will fail and return immediately if:
262 The calling process has no existing unwaited-for
269 arguments point to an illegal address.
270 (May not be detected before exit of a child process.)
272 The call was interrupted by a caught signal,
273 or the signal did not have the
287 functions are defined by POSIX;
291 are not specified by POSIX.
295 and the ability to restart a pending
297 call are extensions to the POSIX interface.
301 function call appeared in