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. Neither the name of the University nor the names of its contributors
13 .\" may be used to endorse or promote products derived from this software
14 .\" without specific prior written permission.
16 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 .\" @(#)wait.2 8.2 (Berkeley) 4/19/94
41 .Nd wait for processes to change status
47 .Fn wait "int *status"
49 .Fn waitpid "pid_t wpid" "int *status" "int options"
52 .Fn waitid "idtype_t idtype" "id_t id" "siginfo_t *info" "int options"
56 .Fn wait3 "int *status" "int options" "struct rusage *rusage"
58 .Fn wait4 "pid_t wpid" "int *status" "int options" "struct rusage *rusage"
61 .Fa "idtype_t idtype" "id_t id"
64 .Fa "struct __wrusage *wrusage"
65 .Fa "siginfo_t *infop"
70 function suspends execution of its calling thread until
72 information is available for a child process
73 or a signal is received.
74 On return from a successful
79 area contains information about the process that reported a status change
86 system calls provide a more general interface for programs
87 that need to wait for specific child processes,
88 that need resource utilization statistics accumulated by child processes,
89 or that require options.
90 The other wait functions are implemented using either
97 function is the most general function in this family and its distinct
100 All of the desired process statuses to be waited on must be explicitly
109 functions all implicitly wait for exited and trapped processes,
114 functions require the corresponding
118 flags to be explicitly specified.
119 This allows waiting for processes which have experienced other
120 status changes without having to also handle the exit status from
121 terminated processes.
127 argument which points to a structure defined as:
130 struct rusage wru_self;
131 struct rusage wru_children;
135 This allows the calling process to collect resource usage statistics
136 from both its own child process as well as from its grand children.
137 When no resource usage statistics are needed this pointer can be
149 the structure is filled with the same data as for a
151 signal delivered when the process changed state.
153 The set of child processes to be queried is specified by the arguments
161 arguments support many other types of
162 identifiers in addition to process IDs and process group IDs.
163 .Bl -bullet -offset indent
172 wait for the child process with a process ID equal to
182 wait for the child process with a process group ID equal to
192 wait for any child process and the
208 wait for any child process in the same process group as the caller.
211 Non-standard identifier types supported by this
217 .Bl -tag -width P_JAILID
219 Wait for processes whose effective user ID is equal to
222 Wait for processes whose effective group ID is equal to
225 Wait for processes whose session ID is equal to
227 .\" This is just how sessions work, not sure this needs to be documented here
228 If the child process started its own session,
229 its session ID will be the same as its process ID.
230 Otherwise the session ID of a child process will match the caller's session ID.
232 Waits for processes within a jail whose jail identifier is equal to
240 functions, the single
242 argument specifies the set of child processes for which to wait.
243 .Bl -bullet -offset indent
247 is -1, the call waits for any child process.
252 the call waits for any child process in the process group of the caller.
256 is greater than zero, the call waits for the process with process ID
261 is less than -1, the call waits for any process whose process group ID
262 equals the absolute value of
268 argument is defined below.
272 argument contains the bitwise OR of any of the following options.
273 .Bl -tag -width WCONTINUED
275 Report the status of selected processes that
276 have continued from a job control stop by receiving a
281 there are no processes wishing to report status.
283 Report the status of selected processes which are stopped due to a
284 .Dv SIGTTIN , SIGTTOU , SIGTSTP ,
292 Report the status of selected processes which are being traced via
294 and have trapped or reached a breakpoint.
295 This flag is implicitly set for the functions
306 functions, the flag has to be explicitly included in
308 if status reports from trapped processes are expected.
310 Report the status of selected processes which have terminated.
311 This flag is implicitly set for the functions
322 functions, the flag has to be explicitly included in
324 if status reports from terminated processes are expected.
326 Keep the process whose status is returned in a waitable state.
327 The process may be waited for again after this call completes.
334 functions, at least one of the options
342 Otherwise there will be no events for the call to report.
343 To avoid hanging indefinitely in such a case these functions
351 is non-NULL, a summary of the resources used by the terminated
352 process and all its children is returned.
356 is non-NULL, separate summaries are returned for the resources used
357 by the terminated process and the resources used by all its children.
363 structure is returned with the
369 field set to the process ID of the process reporting status.
370 For the exited process, the
374 structure contains the full 32 bit exit status passed to
378 argument of other calls only returns 8 lowest bits of the exit status.
382 option is specified and no processes
383 wish to report status,
392 Checking these fields is the only way to know if a status change was reported.
396 option is specified and no processes
397 wish to report status,
421 function is identical to
436 function is identical to
449 The following macros may be used to test the current status of the process.
450 Exactly one of the following four macros will evaluate to a non-zero
454 .It Fn WIFCONTINUED status
455 True if the process has not terminated, and
456 has continued after a job control stop.
457 This macro can be true only if the wait call specified the
460 .It Fn WIFEXITED status
461 True if the process terminated normally by a call to
465 .It Fn WIFSIGNALED status
466 True if the process terminated due to receipt of a signal.
467 .It Fn WIFSTOPPED status
468 True if the process has not terminated, but has stopped and can be restarted.
469 This macro can be true only if the wait call specified the
472 or if the child process is being traced (see
476 Depending on the values of those macros, the following macros
477 produce the remaining status information about the child process:
479 .It Fn WEXITSTATUS status
482 is true, evaluates to the low-order 8 bits
483 of the argument passed to
488 .It Fn WTERMSIG status
490 .Fn WIFSIGNALED status
491 is true, evaluates to the number of the signal
492 that caused the termination of the process.
493 .It Fn WCOREDUMP status
495 .Fn WIFSIGNALED status
496 is true, evaluates as true if the termination
497 of the process was accompanied by the creation of a core file
498 containing an image of the process when the signal was received.
499 .It Fn WSTOPSIG status
501 .Fn WIFSTOPPED status
502 is true, evaluates to the number of the signal
503 that caused the process to stop.
508 for a list of termination signals.
509 A status of 0 indicates normal termination.
511 If a parent process terminates without
512 waiting for all of its child processes to terminate,
513 the remaining child processes are re-assigned to the reaper
514 of the exiting process as the parent, see
516 .Dv PROC_REAP_ACQUIRE .
517 If no specific reaper was assigned, the process with ID 1, the init process,
518 becomes the parent of the orphaned children by default.
520 If a signal is caught while any of the
523 the call may be interrupted or restarted when the signal-catching routine
525 depending on the options in effect for the signal;
531 The implementation queues one
533 signal for each child process whose
534 status has changed; if
536 returns because the status of a child process is available, the pending
537 SIGCHLD signal associated with the process ID of the child process will
541 signals remain pending.
547 returns because the status of a child process is available, the pending
549 signal will be cleared unless another status of the child process
554 returns due to a stopped, continued,
555 or terminated child process, the process ID of the child
556 is returned to the calling process.
557 Otherwise, a value of \-1
560 is set to indicate the error.
568 returns due to a stopped, continued,
569 or terminated child process, the process ID of the child
570 is returned to the calling process.
571 If there are no children not previously awaited,
578 is specified and there are
579 no stopped, continued or exited children,
581 If an error is detected or a caught signal aborts the call,
585 is set to indicate the error.
589 returns because one or more processes have a state change to report,
591 If an error is detected,
595 is set to indicate the error.
598 is specified and there are
599 no stopped, continued or exited children,
607 must be checked against zero to determine if a process reported status.
611 family of functions will not return a child process created with
613 unless specifically directed to do so by specifying its process ID.
618 will fail and return immediately if:
621 The calling process has no existing unwaited-for
624 No status from the terminated child process is available
625 because the calling process has asked the system to discard
626 such status by ignoring the signal
636 argument points to an illegal address.
637 (May not be detected before exit of a child process.)
639 The call was interrupted by a caught signal,
640 or the signal did not have the
644 An invalid value was specified for
650 do not specify a valid set of processes.
665 functions are defined by POSIX;
670 are not specified by POSIX.
674 is an extension to the POSIX interface.
676 The ability to use the
682 only permits this flag with