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
48 .Fn wait "int *status"
50 .Fn waitpid "pid_t wpid" "int *status" "int options"
53 .Fn waitid "idtype_t idtype" "id_t id" "siginfo_t *info" "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"
61 .Fn wait6 "idtype_t idtype" "id_t id" "int *status" "int options" "struct __wrusage *wrusage" "siginfo_t *infop"
65 function suspends execution of its calling thread until
67 information is available for a child process
68 or a signal is received.
69 On return from a successful
74 area contains information about the process that reported a status change
81 system calls provide a more general interface for programs
82 that need to wait for specific child processes,
83 that need resource utilization statistics accumulated by child processes,
84 or that require options.
85 The other wait functions are implemented using either
92 function is the most general function in this family and its distinct
95 All of the desired process statuses to be waited on must be explicitly
104 functions all implicitly wait for exited and trapped processes,
109 functions require the corresponding
113 flags to be explicitly specified.
114 This allows waiting for processes which have experienced other
115 status changes without having to also handle the exit status from
116 terminated processes.
122 argument which points to a structure defined as:
125 struct rusage wru_self;
126 struct rusage wru_children;
130 This allows the calling process to collect resource usage statistics
131 from both its own child process as well as from its grand children.
132 When no resource usage statistics are needed this pointer can be
144 the structure is filled with the same data as for a
146 signal delivered when the process changed state.
148 The set of child processes to be queried is specified by the arguments
156 arguments support many other types of
157 identifiers in addition to process IDs and process group IDs.
158 .Bl -bullet -offset indent
167 wait for the child process with a process ID equal to
168 .Vt ( pid_t ) Fa id .
177 wait for the child process with a process group ID equal to
178 .Vt ( pid_t ) Fa id .
187 wait for any child process and the
203 wait for any child process in the same process group as the caller.
206 Non-standard identifier types supported by this
212 .Bl -tag -width P_JAILID
214 Wait for processes whose effective user ID is equal to
215 .Vt ( uid_t ) Fa id .
217 Wait for processes whose effective group ID is equal to
218 .Vt ( gid_t ) Fa id .
220 Wait for processes whose session ID is equal to
222 .\" This is just how sessions work, not sure this needs to be documented here
223 If the child process started its own session,
224 its session ID will be the same as its process ID.
225 Otherwise the session ID of a child process will match the caller's session ID.
227 Waits for processes within a jail whose jail identifier is equal to
235 functions, the single
237 argument specifies the set of child processes for which to wait.
238 .Bl -bullet -offset indent
242 is -1, the call waits for any child process.
247 the call waits for any child process in the process group of the caller.
251 is greater than zero, the call waits for the process with process ID
256 is less than -1, the call waits for any process whose process group ID
257 equals the absolute value of
263 argument is defined below.
267 argument contains the bitwise OR of any of the following options.
268 .Bl -tag -width WCONTINUED
270 Report the status of selected processes that
271 have continued from a job control stop by receiving a
276 there are no processes wishing to report status.
278 Report the status of selected processes which are stopped due to a
279 .Dv SIGTTIN , SIGTTOU , SIGTSTP ,
287 Report the status of selected processes which are being traced via
289 and have trapped or reached a breakpoint.
290 This flag is implicitly set for the functions
301 functions, the flag has to be explicitly included in
303 if status reports from trapped processes are expected.
305 Report the status of selected processes which have terminated.
306 This flag is implicitly set for the functions
317 functions, the flag has to be explicitly included in
319 if status reports from terminated processes are expected.
321 Keep the process whose status is returned in a waitable state.
322 The process may be waited for again after this call completes.
329 functions, at least one of the options
337 Otherwise there will be no events for the call to report.
338 To avoid hanging indefinitely in such a case these functions
346 is non-NULL, a summary of the resources used by the terminated
347 process and all its children is returned.
351 is non-NULL, separate summaries are returned for the resources used
352 by the terminated process and the resources used by all its children.
358 structure is returned with the
364 field set to the process ID of the process reporting status.
365 For the exited process, the
369 structure contains the fully decoded exit code passed to
371 Note that exit codes are limited to the values 0-255.
372 For a process killed by a signal, the
374 field contains the fully decoded signal.
376 The si_code field of the
378 structure may be set to the following values:
381 Child exited with an exit code.
383 Child terminated abnormally with a signal.
385 Child terminated abnormally and dumped (not implemented by DragonFly).
387 Traced child has trapped.
391 Child has been resumed.
396 option is specified and no processes
397 wish to report status,
406 Checking these fields is the only way to know if a status change was reported.
410 option is specified and no processes
411 wish to report status,
435 function is identical to
450 function is identical to
463 The following macros may be used to test the current status of the process.
464 Exactly one of the following four macros will evaluate to a non-zero
468 .It Fn WIFCONTINUED status
469 True if the process has not terminated, and
470 has continued after a job control stop.
471 This macro can be true only if the wait call specified the
474 .It Fn WIFEXITED status
475 True if the process terminated normally by a call to
479 .It Fn WIFSIGNALED status
480 True if the process terminated due to receipt of a signal.
481 .It Fn WIFSTOPPED status
482 True if the process has not terminated, but has stopped and can be restarted.
483 This macro can be true only if the wait call specified the
486 or if the child process is being traced (see
490 Depending on the values of those macros, the following macros
491 produce the remaining status information about the child process:
493 .It Fn WEXITSTATUS status
496 is true, evaluates to the low-order 8 bits
497 of the argument passed to
502 .It Fn WTERMSIG status
504 .Fn WIFSIGNALED status
505 is true, evaluates to the number of the signal
506 that caused the termination of the process.
507 .It Fn WCOREDUMP status
509 .Fn WIFSIGNALED status
510 is true, evaluates as true if the termination
511 of the process was accompanied by the creation of a core file
512 containing an image of the process when the signal was received.
513 .It Fn WSTOPSIG status
515 .Fn WIFSTOPPED status
516 is true, evaluates to the number of the signal
517 that caused the process to stop.
522 for a list of termination signals.
523 A status of 0 indicates normal termination.
525 If a parent process terminates without
526 waiting for all of its child processes to terminate,
527 the remaining child processes are assigned the parent
528 process 1 ID (the init process ID).
530 If a signal is caught while any of the
533 the call may be interrupted or restarted when the signal-catching routine
535 depending on the options in effect for the signal;
541 The implementation queues one
543 signal for each child process whose
544 status has changed; if
546 returns because the status of a child process is available, the pending
547 SIGCHLD signal associated with the process ID of the child process will
551 signals remain pending.
557 returns because the status of a child process is available, the pending
559 signal will be cleared unless another status of the child process
564 returns due to a stopped, continued,
565 or terminated child process, the process ID of the child
566 is returned to the calling process.
567 Otherwise, a value of \-1
570 is set to indicate the error.
578 returns due to a stopped, continued,
579 or terminated child process, the process ID of the child
580 is returned to the calling process.
581 If there are no children not previously awaited,
588 is specified and there are
589 no stopped, continued or exited children,
591 If an error is detected or a caught signal aborts the call,
595 is set to indicate the error.
599 returns because one or more processes have a state change to report,
601 If an error is detected,
605 is set to indicate the error.
608 is specified and there are
609 no stopped, continued or exited children,
617 must be checked against zero to determine if a process reported status.
620 called with -1 to wait for any child process will ignore a child that is
621 referenced by a process descriptor (see
623 Specific processes can still be waited on by specifying the process ID.
628 will fail and return immediately if:
631 The calling process has no existing unwaited-for
634 No status from the terminated child process is available
635 because the calling process has asked the system to discard
636 such status by ignoring the signal
646 argument points to an illegal address.
647 (May not be detected before exit of a child process.)
649 The call was interrupted by a caught signal,
650 or the signal did not have the
654 An invalid value was specified for
660 do not specify a valid set of processes.
674 functions are defined by POSIX;
679 are not specified by POSIX.
683 is an extension to the POSIX interface.
685 The ability to use the
691 only permits this flag with