1 .\" $NetBSD: wait.2,v 1.27 2010/04/03 15:43:46 jruoho 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. Neither the name of the University nor the names of its contributors
15 .\" may be used to endorse or promote products derived from this software
16 .\" without specific prior written permission.
18 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 .\" @(#)wait.2 8.2 (Berkeley) 4/19/94
40 .Nd wait for process termination
46 .Fn wait "int *status"
48 .Fn waitpid "pid_t wpid" "int *status" "int options"
51 .Fn wait3 "int *status" "int options" "struct rusage *rusage"
53 .Fn wait4 "pid_t wpid" "int *status" "int options" "struct rusage *rusage"
57 function suspends execution of its calling process until
59 information is available for a terminated child process,
60 or a signal is received.
61 On return from a successful
66 area contains termination information about the process that exited
71 call provides a more general interface for programs
72 that need to wait for certain child processes,
73 that need resource utilization statistics accumulated by child processes,
74 or that require options.
75 The other wait functions are implemented using
80 parameter specifies the set of child processes for which to wait.
83 is \-1, the call waits for any child process.
87 the call waits for any child process in the process group of the caller.
90 is greater than zero, the call waits for the process with process id
94 is less than \-1, the call waits for any process whose process group id
95 equals the absolute value of
100 parameter is defined below.
104 parameter contains the bitwise OR of any of the following options:
105 .Bl -tag -width WUNTRACED
107 This option is used to indicate that the call should not block if
108 there are no processes that wish to report status.
110 If this option is set, children of the current process that are stopped
112 .Dv SIGTTIN , SIGTTOU , SIGTSTP ,
115 signal also have their status reported.
117 If this option is specified, the call will wait only for processes that
118 are configured to post a signal other than
123 is not specified, the call will wait only for processes that
124 are configured to post
129 It is provided for compatibility with the Linux
133 If this option is specified, the call will wait for all children regardless
134 of what exit signal they post.
138 It is provided for compatibility with the Linux
145 is non-zero, a summary of the resources used by the terminated
147 children is returned (this information is currently not available
148 for stopped processes).
152 option is specified and no processes
153 wish to report status,
174 The following macros may be used to test the manner of exit of the process.
175 Note that these macros expect the
177 value itself, not a pointer to the
180 One of the first three macros will evaluate to a non-zero (true) value:
182 .It Fn WIFEXITED status
183 True if the process terminated normally by a call to
187 .It Fn WIFSIGNALED status
188 True if the process terminated due to receipt of a signal.
189 .It Fn WIFSTOPPED status
190 True if the process has not terminated, but has stopped and can be restarted.
191 This macro can be true only if the wait call specified the
194 or if the child process is being traced (see
198 Depending on the values of those macros, the following macros
199 produce the remaining status information about the child process:
201 .It Fn WEXITSTATUS status
204 is true, evaluates to the low-order 8 bits
205 of the argument passed to
210 .It Fn WTERMSIG status
212 .Fn WIFSIGNALED status
213 is true, evaluates to the number of the signal
214 that caused the termination of the process.
215 .It Fn WCOREDUMP status
217 .Fn WIFSIGNALED status
218 is true, evaluates as true if the termination
219 of the process was accompanied by the creation of a core file
220 containing an image of the process when the signal was received.
221 .It Fn WSTOPSIG status
223 .Fn WIFSTOPPED status
224 is true, evaluates to the number of the signal
225 that caused the process to stop.
230 for a list of termination signals.
231 A status of 0 indicates normal termination.
233 If a parent process terminates without
234 waiting for all of its child processes to terminate,
235 the remaining child processes are assigned the parent
236 process 1 ID (the init process ID).
238 If a signal is caught while any of the
241 the call may be interrupted or restarted when the signal-catching routine
243 depending on the options in effect for the signal;
250 returns due to a stopped
251 or terminated child process, the process ID of the child
252 is returned to the calling process.
253 Otherwise, a value of \-1 is returned and
255 is set to indicate the error.
262 returns due to a stopped
263 or terminated child process, the process ID of the child
264 is returned to the calling process.
265 If there are no children not previously awaited,
272 is specified and there are
273 no stopped or exited children, 0 is returned.
274 If an error is detected or a caught signal aborts the call,
275 a value of \-1 is returned and
277 is set to indicate the error.
280 will fail and return immediately if:
283 The calling process has no existing unwaited-for child processes.
289 arguments point to an illegal address.
290 (May not be detected before exit of a child process.)
292 The call was interrupted by a caught signal,
293 or the signal did not have the
303 will fail and return immediately if:
306 An invalid value was specified for
328 and the ability to restart a pending
330 call are extensions to the POSIX interface.
334 function call appeared in