1WAIT(2)                    Linux Programmer's Manual                   WAIT(2)
2
3
4

NAME

6       wait, waitpid, waitid - wait for process to change state
7

SYNOPSIS

9       #include <sys/types.h>
10       #include <sys/wait.h>
11
12       pid_t wait(int *wstatus);
13
14       pid_t waitpid(pid_t pid, int *wstatus, int options);
15
16       int waitid(idtype_t idtype, id_t id, siginfo_t *infop, int options);
17                       /* This is the glibc and POSIX interface; see
18                          NOTES for information on the raw system call. */
19
20   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
21
22       waitid():
23           Since glibc 2.26: _XOPEN_SOURCE >= 500 ||
24               _POSIX_C_SOURCE >= 200809L
25           Glibc 2.25 and earlier:
26               _XOPEN_SOURCE
27                   || /* Since glibc 2.12: */ _POSIX_C_SOURCE >= 200809L
28                   || /* Glibc versions <= 2.19: */ _BSD_SOURCE
29

DESCRIPTION

31       All of these system calls are used to wait for state changes in a child
32       of the calling process, and obtain information about  the  child  whose
33       state  has changed.  A state change is considered to be: the child ter‐
34       minated; the child was stopped by a signal; or the child was resumed by
35       a  signal.  In the case of a terminated child, performing a wait allows
36       the system to release the resources associated with  the  child;  if  a
37       wait  is not performed, then the terminated child remains in a "zombie"
38       state (see NOTES below).
39
40       If a child has already changed state, then these calls  return  immedi‐
41       ately.   Otherwise,  they block until either a child changes state or a
42       signal handler interrupts the call (assuming that system calls are  not
43       automatically restarted using the SA_RESTART flag of sigaction(2)).  In
44       the remainder of this page, a child whose state has changed  and  which
45       has  not  yet  been  waited upon by one of these system calls is termed
46       waitable.
47
48   wait() and waitpid()
49       The wait() system call suspends execution of the calling  thread  until
50       one  of its children terminates.  The call wait(&wstatus) is equivalent
51       to:
52
53           waitpid(-1, &wstatus, 0);
54
55       The waitpid() system call suspends  execution  of  the  calling  thread
56       until a child specified by pid argument has changed state.  By default,
57       waitpid() waits only for terminated children, but this behavior is mod‐
58       ifiable via the options argument, as described below.
59
60       The value of pid can be:
61
62       < -1   meaning  wait  for  any  child process whose process group ID is
63              equal to the absolute value of pid.
64
65       -1     meaning wait for any child process.
66
67       0      meaning wait for any child process whose  process  group  ID  is
68              equal to that of the calling process.
69
70       > 0    meaning  wait  for  the  child  whose process ID is equal to the
71              value of pid.
72
73       The value of options is an OR of zero or more  of  the  following