1 .\" $OpenBSD: wait.2,v 1.21 2007/05/31 19:19:34 jmc Exp $
2 .\" $NetBSD: wait.2,v 1.6 1995/02/27 12:39:37 cgd Exp $
4 .\" Copyright (c) 1980, 1991, 1993, 1994
5 .\" The Regents of the University of California. All rights reserved.
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that the following conditions
10 .\" 1. Redistributions of source code must retain the above copyright
11 .\" notice, this list of conditions and the following disclaimer.
12 .\" 2. Redistributions in binary form must reproduce the above copyright
13 .\" notice, this list of conditions and the following disclaimer in the
14 .\" documentation and/or other materials provided with the distribution.
15 .\" 3. Neither the name of the University nor the names of its contributors
16 .\" may be used to endorse or promote products derived from this software
17 .\" without specific prior written permission.
19 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 .\" @(#)wait.2 8.2 (Berkeley) 4/19/94
33 .Dd $Mdocdate: May 31 2007 $
41 .Nd wait for process termination
43 .Fd #include <sys/types.h>
44 .Fd #include <sys/wait.h>
46 .Fn wait "int *status"
48 .Fn waitpid "pid_t wpid" "int *status" "int options"
49 .Fd #include <sys/time.h>
50 .Fd #include <sys/resource.h>
52 .Fn wait3 "int *status" "int options" "struct rusage *rusage"
54 .Fn wait4 "pid_t wpid" "int *status" "int options" "struct rusage *rusage"
58 function suspends execution of its calling process until
60 information is available for a terminated child process,
61 or a signal is received.
62 On return from a successful
66 area, if non-zero, is filled in with termination information about the
67 process that exited (see below).
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.
81 The following symbolic constants are currently defined in
83 .Bd -unfilled -offset indent
84 #define WAIT_ANY (-1) /* any process */
85 #define WAIT_MYPGRP 0 /* any process in my process group */
92 the call waits for any child process.
97 the call waits for any child process in the process group of the caller.
100 is greater than zero, the call waits for the process with process ID
104 is less than \-1, the call waits for any process whose process group ID
105 equals the absolute value of
110 parameter is defined below.
113 parameter contains the bitwise
115 of any of the following options:
116 .Bl -tag -width "WCONTINUED"
118 Causes status to be reported for stopped child processes that have been
119 continued by receipt of a
123 Indicates that the call should not block if there are no processes that wish
126 If set, children of the current process that are stopped due to a
127 .Dv SIGTTIN , SIGTTOU , SIGTSTP ,
130 signal also have their status reported.
135 is non-zero, a summary of the resources used by the terminated
137 children is returned (this information is currently not available
138 for stopped processes).
142 option is specified and no processes wish to report status,
144 returns a process ID of 0.
161 The following macros may be used to test the manner of exit of the process.
162 One of the first three macros will evaluate to a non-zero (true) value:
164 .It Fn WIFCONTINUED status
165 True if the process has not terminated, and has continued after a job
167 This macro can be true only if the wait call specified the
170 .It Fn WIFEXITED status
171 True if the process terminated normally by a call to
175 .It Fn WIFSIGNALED status
176 True if the process terminated due to receipt of a signal.
177 .It Fn WIFSTOPPED status
178 True if the process has not terminated, but has stopped and can be restarted.
179 This macro can be true only if the wait call specified the
181 option 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 of the argument passed to
196 .It Fn WTERMSIG status
198 .Fn WIFSIGNALED status
199 is true, evaluates to the number of the signal
200 that caused the termination of the process.
201 .It Fn WCOREDUMP status
203 .Fn WIFSIGNALED status
204 is true, evaluates as true if the termination
205 of the process was accompanied by the creation of a core file
206 containing an image of the process when the signal was received.
207 .It Fn WSTOPSIG status
209 .Fn WIFSTOPPED status
210 is true, evaluates to the number of the signal that caused the process
216 for a list of termination signals.
217 A status of 0 indicates normal termination.
219 If a parent process terminates without
220 waiting for all of its child processes to terminate,
221 the remaining child processes are assigned the parent
222 process 1 ID (the init process ID).
224 If a signal is caught while any of the
226 calls is pending, the call may be interrupted or restarted when the
227 signal-catching routine returns, depending on the options in effect
228 for the signal; for further information, see
233 returns due to a stopped
234 or terminated child process, the process ID of the child
235 is returned to the calling process.
236 Otherwise, a value of \-1 is returned and
238 is set to indicate the error.
245 returns due to a stopped or terminated child process, the process ID
246 of the child is returned to the calling process.
247 If there are no children not previously awaited, \-1 is returned with
253 is specified and there are no stopped or exited children, 0 is returned.
254 If an error is detected or a caught signal aborts the call, a value of \-1
257 is set to indicate the error.
260 will fail and return immediately if:
263 The calling process has no existing unwaited-for child processes.
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, or the signal did not have the
276 Invalid or undefined flags were passed in the
289 functions are defined by POSIX;
293 are not specified by POSIX.
296 macro and the ability to restart a pending
298 call are extensions to the POSIX interface.
302 function call appeared in