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/types.h>
47 .Fd #include <sys/wait.h>
49 .Fn wait "int *status"
51 .Fn waitpid "pid_t wpid" "int *status" "int options"
52 .Fd #include <sys/time.h>
53 .Fd #include <sys/resource.h>
55 .Fn wait3 "int *status" "int options" "struct rusage *rusage"
57 .Fn wait4 "pid_t wpid" "int *status" "int options" "struct rusage *rusage"
61 function suspends execution of its calling process until
63 information is available for a terminated child process,
64 or a signal is received.
65 On return from a successful
70 area contains termination information about the process that exited
75 call provides a more general interface for programs
76 that need to wait for certain child processes,
77 that need resource utilization statistics accumulated by child processes,
78 or that require options.
79 The other wait functions are implemented using
84 parameter specifies the set of child processes for which to wait.
87 is -1, the call waits for any child process.
91 the call waits for any child process in the process group of the caller.
94 is greater than zero, the call waits for the process with process id
98 is less than -1, the call waits for any process whose process group id
99 equals the absolute value of
104 parameter is defined below. The
106 parameter contains the bitwise OR of any of the following options.
110 is used to indicate that the call should not block if
111 there are no processes that wish to report status.
115 children of the current process that are stopped
117 .Dv SIGTTIN , SIGTTOU , SIGTSTP ,
121 their status reported.
125 is non-zero, a summary of the resources used by the terminated
127 children is returned (this information is currently not available
128 for stopped processes).
132 option is specified and no processes
133 wish to report status,
154 The following macros may be used to test the manner of exit of the process.
155 One of the first three macros will evaluate to a non-zero (true) value:
157 .It Fn WIFEXITED status
158 True if the process terminated normally by a call to
162 .It Fn WIFSIGNALED status
163 True if the process terminated due to receipt of a signal.
164 .It Fn WIFSTOPPED status
165 True if the process has not terminated, but has stopped and can be restarted.
166 This macro can be true only if the wait call specified the
169 or if the child process is being traced (see
173 Depending on the values of those macros, the following macros
174 produce the remaining status information about the child process:
176 .It Fn WEXITSTATUS status
179 is true, evaluates to the low-order 8 bits
180 of the argument passed to
185 .It Fn WTERMSIG status
187 .Fn WIFSIGNALED status
188 is true, evaluates to the number of the signal
189 that caused the termination of the process.
190 .It Fn WCOREDUMP status
192 .Fn WIFSIGNALED status
193 is true, evaluates as true if the termination
194 of the process was accompanied by the creation of a core file
195 containing an image of the process when the signal was received.
196 .It Fn WSTOPSIG status
198 .Fn WIFSTOPPED status
199 is true, evaluates to the number of the signal
200 that caused the process to stop.
205 for a list of termination signals.
206 A status of 0 indicates normal termination.
208 If a parent process terminates without
209 waiting for all of its child processes to terminate,
210 the remaining child processes are assigned the parent
211 process 1 ID (the init process ID).
213 If a signal is caught while any of the
216 the call may be interrupted or restarted when the signal-catching routine
218 depending on the options in effect for the signal;
225 returns due to a stopped
226 or terminated child process, the process ID of the child
227 is returned to the calling process. Otherwise, a value of -1
230 is set to indicate the error.
237 returns due to a stopped
238 or terminated child process, the process ID of the child
239 is returned to the calling process.
240 If there are no children not previously awaited,
247 is specified and there are
248 no stopped or exited children,
250 If an error is detected or a caught signal aborts the call,
254 is set to indicate the error.
257 will fail and return immediately if:
260 The calling process has no existing unwaited-for
267 arguments point to an illegal address.
268 (May not be detected before exit of a child process.)
270 The call was interrupted by a caught signal,
271 or the signal did not have the
275 Invalid or underfined flags were passed in the
284 functions are defined by POSIX;
288 are not specified by POSIX.
292 and the ability to restart a pending
294 call are extensions to the POSIX interface.
301 function call appeared in