1wait(3C) Standard C Library Functions wait(3C)
2
3
4
6 wait - wait for child process to stop or terminate
7
9 #include <sys/types.h>
10 #include <sys/wait.h>
11
12 pid_t wait(int *stat_loc);
13
14
16 The wait() function will suspend execution of the calling thread until
17 status information for one of its terminated child processes is avail‐
18 able, or until delivery of a signal whose action is either to execute a
19 signal-catching function or to terminate the process. If more than one
20 thread is suspended in wait(), waitpid(3C), or waitid(2) awaiting ter‐
21 mination of the same process, exactly one thread will return the
22 process status at the time of the target process termination. If status
23 information is available prior to the call to wait(), return will be
24 immediate.
25
26
27 If wait() returns because the status of a child process is available,
28 it returns the process ID of the child process. If the calling process
29 specified a non-zero value for stat_loc, the status of the child
30 process is stored in the location pointed to by stat_loc. That status
31 can be evaluated with the macros described on the wait.h(3HEAD) manual
32 page.
33
34
35 In the following, status is the object pointed to by stat_loc:
36
37 o If the child process terminated due to an _exit() call, the
38 low order 8 bits of status will be 0 and the high order 8
39 bits will contain the low order 7 bits of the argument that
40 the child process passed to _exit(); see exit(2).
41
42 o If the child process terminated due to a signal, the high
43 order 8 bits of status will be 0 and the low order 7bits
44 will contain the number of the signal that caused the termi‐
45 nation. In addition, if WCOREFLG is set, a "core image"
46 will have been produced; see signal.h(3HEAD) and
47 wait.h(3HEAD).
48
49
50 One instance of a SIGCHLD signal is queued for each child process whose
51 status has changed. If wait() returns because the status of a child
52 process is available, any pending SIGCHLD signal associated with the
53 process ID of that child process is discarded. Any other pending
54 SIGCHLD signals remain pending.
55
56
57 If the calling process has SA_NOCLDWAIT set or has SIGCHLD set to
58 SIG_IGN, and the process has no unwaited children that were transformed
59 into zombie processes, it will block until all of its children termi‐
60 nate, and wait() will fail and set errno to ECHILD.
61
62
63 If a parent process terminates without waiting for its child processes
64 to terminate, the parent process ID of each child process is set to 1,
65 with the initialization process inheriting the child processes; see
66 Intro(2).
67
69 When wait() returns due to a terminated child process, the process ID
70 of the child is returned to the calling process. Otherwise, −1 is
71 returned and errno is set to indicate the error.
72
74 The wait() function will fail if:
75
76 ECHILD The calling process has no existing unwaited-for child pro‐
77 cesses.
78
79
80 EINTR The function was interrupted by a signal.
81
82
84 Since wait() blocks on a stopped child, a calling process wanting to
85 see the return results of such a call should use waitpid(3C) or
86 waitid(2) instead of wait(). The wait() function is implemented as a
87 call to waitpid(-1, stat_loc, 0).
88
90 See attributes(5) for descriptions of the following attributes:
91
92
93
94
95 ┌─────────────────────────────┬─────────────────────────────┐
96 │ ATTRIBUTE TYPE │ ATTRIBUTE VALUE │
97 ├─────────────────────────────┼─────────────────────────────┤
98 │Interface Stability │Standard │
99 ├─────────────────────────────┼─────────────────────────────┤
100 │MT-Level │Async-Signal-Safe │
101 └─────────────────────────────┴─────────────────────────────┘
102
104 Intro(2), exec(2), exit(2), fork(2), pause(2), waitid(2), ptrace(3C),
105 signal(3C), signal.h(3HEAD), waitpid(3C), wait.h(3HEAD), attributes(5)
106
107
108
109SunOS 5.11 9 Jun 2004 wait(3C)