1WAIT(2) Linux Programmer's Manual WAIT(2)
2
3
4
6 wait, waitpid, waitid - wait for process to change state
7
9 #include <sys/wait.h>
10
11 pid_t wait(int *wstatus);
12 pid_t waitpid(pid_t pid, int *wstatus, int options);
13
14 int waitid(idtype_t idtype, id_t id, siginfo_t *infop, int options);
15 /* This is the glibc and POSIX interface; see
16 NOTES for information on the raw system call. */
17
18 Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
19
20 waitid():
21 Since glibc 2.26:
22 _XOPEN_SOURCE >= 500 || _POSIX_C_SOURCE >= 200809L
23 Glibc 2.25 and earlier:
24 _XOPEN_SOURCE
25 || /* Since glibc 2.12: */ _POSIX_C_SOURCE >= 200809L
26 || /* Glibc <= 2.19: */ _BSD_SOURCE
27
29 All of these system calls are used to wait for state changes in a child
30 of the calling process, and obtain information about the child whose
31 state has changed. A state change is considered to be: the child ter‐
32 minated; the child was stopped by a signal; or the child was resumed by
33 a signal. In the case of a terminated child, performing a wait allows
34 the system to release the resources associated with the child; if a
35 wait is not performed, then the terminated child remains in a "zombie"
36 state (see NOTES below).
37
38 If a child has already changed state, then these calls return immedi‐
39 ately. Otherwise, they block until either a child changes state or a
40 signal handler interrupts the call (assuming that system calls are not
41 automatically restarted using the SA_RESTART flag of sigaction(2)). In
42 the remainder of this page, a child whose state has changed and which
43 has not yet been waited upon by one of these system calls is termed
44 waitable.
45
46 wait() and waitpid()
47 The wait() system call suspends execution of the calling thread until
48 one of its children terminates. The call wait(&wstatus) is equivalent
49 to:
50
51 waitpid(-1, &wstatus, 0);
52
53 The waitpid() system call suspends execution of the calling thread un‐
54 til a child specified by pid argument has changed state. By default,
55 waitpid() waits only for terminated children, but this behavior is mod‐
56 ifiable via the options argument, as described below.
57
58 The value of pid can be:
59
60 < -1 meaning wait for any child process whose process group ID is
61 equal to the absolute value of pid.
62
63 -1 meaning wait for any child process.
64
65 0 meaning wait for any child process whose process group ID is
66 equal to that of the calling process at the time of the call to
67 waitpid().
68
69 > 0 meaning wait for the child whose process ID is equal to the
70 value of pid.
71
72 The value of options is an OR of zero or more of the following con‐