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