Penguin
Annotated edit history of wait(2) version 4 showing authors affecting page license. View with all changes included.
Rev Author # Line
1 perry 1 WAIT
2 !!!WAIT
3 NAME
4 SYNOPSIS
5 DESCRIPTION
6 RETURN VALUE
7 ERRORS
8 NOTES
9 CONFORMING TO
10 SEE ALSO
11 ----
12 !!NAME
13
14
15 wait, waitpid - wait for process termination
16 !!SYNOPSIS
17
18
19 __#include __
20 #include __
21
22
23 __pid_t wait(int *__''status''__)
24 pid_t waitpid(pid_t__ ''pid''__, int
25 *__''status''__, int__
26 ''options''__);__
27 !!DESCRIPTION
28
29
30 The __wait__ function suspends execution of the current
31 process until a child has exited, or until a signal is
32 delivered whose action is to terminate the current process
33 or to call a signal handling function. If a child has
34 already exited by the time of the call (a so-called
35 __
36
37
38 The __waitpid__ function suspends execution of the
39 current process until a child as specified by the ''pid''
40 argument has exited, or until a signal is delivered whose
41 action is to terminate the current process or to call a
42 signal handling function. If a child as requested by
43 ''pid'' has already exited by the time of the call (a
44 so-called
45 ''
46
47
48 The value of ''pid'' can be one of:
49
50
51
52
53 which means to wait for any child process whose process
54 group ID is equal to the absolute value of
55 ''pid''.
56
57
58 -1
59
60
61 which means to wait for any child process; this is the same
62 behaviour which __wait__ exhibits.
63
64
65 0
66
67
68 which means to wait for any child process whose process
69 group ID is equal to that of the calling
70 process.
71
72
73
74
75 which means to wait for the child whose process ID is equal
76 to the value of ''pid''.
77
78
79 The value of ''options'' is an OR of zero or more of the
80 following constants:
81
82
83 __WNOHANG__
84
85
86 which means to return immediately if no child has
87 exited.
88
89
90 __WUNTRACED__
91
92
93 which means to also return for children which are stopped,
94 and whose status has not been reported.
95
96
97 If ''status'' is not __NULL__, __wait__ or
98 __waitpid__ store status information in the location
99 pointed to by ''status''.
100
101
102 This status can be evaluated with the following macros
103 (these macros take the stat buffer (an __int__) as an
104 argument -- not a pointer to the buffer!):
105
106
107 __WIFEXITED(__''status''__)__
108
109
110 is non-zero if the child exited normally.
111
112
113 __WEXITSTATUS(__''status''__)__
114
115
116 evaluates to the least significant eight bits of the return
117 code of the child which terminated, which may have been set
118 as the argument to a call to __exit()__ or as the
119 argument for a __return__ statement in the main program.
120 This macro can only be evaluated if __WIFEXITED__
121 returned non-zero.
122
123
124 __WIFSIGNALED(__''status''__)__
125
126
127 returns true if the child process exited because of a signal
128 which was not caught.
129
130
131 __WTERMSIG(__''status''__)__
132
133
134 returns the number of the signal that caused the child
135 process to terminate. This macro can only be evaluated if
136 __WIFSIGNALED__ returned non-zero.
137
138
139 __WIFSTOPPED(__''status''__)__
140
141
142 returns true if the child process which caused the return is
143 currently stopped; this is only possible if the call was
144 done using __WUNTRACED__.
145
146
147 __WSTOPSIG(__''status''__)__
148
149
150 returns the number of the signal which caused the child to
151 stop. This macro can only be evaluated if __WIFSTOPPED__
152 returned non-zero.
153
154
155 Some versions of Unix (e.g. Linux, Solaris, but not AIX,
156 SunOS) also define a macro
157 __WCOREDUMP(__''status''__)__ to test whether the
158 child process dumped core. Only use this enclosed in #ifdef
159 WCOREDUMP ... #endif.
160 !!RETURN VALUE
161
162
163 The process ID of the child which exited, or zero if
164 __WNOHANG__ was used and no child was available, or -1 on
165 error (in which case ''errno'' is set to an appropriate
166 value).
167 !!ERRORS
168
169
170 __ECHILD__
171
172
173 if the process specified in ''pid'' does not exist or is
174 not a child of the calling process. (This can happen for
175 one's own child if the action for SIGCHLD is set to SIG_IGN.
176 See also the NOTES section about threads.)
177
178
179 __EINVAL__
180
181
182 if the ''options'' argument was invalid.
183
184
185 __EINTR__
186
187
188 if __WNOHANG__ was not set and an unblocked signal or a
189 __SIGCHLD__ was caught.
190 !!NOTES
191
192
193 The Single Unix Specification describes a flag SA_NOCLDWAIT
194 (not present under Linux) such that if either this flag is
195 set, or the action for SIGCHLD is set to SIG_IGN (which, by
196 the way, is not allowed by POSIX), then children that exit
197 do not become zombies and a call to ''wait()'' or
198 ''waitpid()'' will block until all children have exited,
199 and then fail with ''errno'' set to ECHILD.
200
201
202 In the Linux kernel, a kernel-scheduled thread is not a
203 distinct construct from a process. Instead, a thread is
204 simply a process that is created using the Linux-unique
205 clone(2) system call; other routines such as the portable
206 pthread_create(3) call are implemented using
207 clone(2). Thus, if two threads A and B are siblings,
208 then thread A cannot wait on any processes forked by thread
209 B or its descendents, because an uncle cannot wait on his
210 nephews. In some other Unix-like systems, where multiple
211 threads are implemented as belonging to a single process,
212 thread A can wait on any processes forked by sibling thread
213 B; you will have to rewrite any code that makes this
214 assumption for it to work on Linux.
215 !!CONFORMING TO
216
217
218 SVr4, POSIX.1
219 !!SEE ALSO
220
221
222 clone(2), signal(2), wait4(2),
223 pthread_create(3), signal(7)
224 ----
This page is a man page (or other imported legacy content). We are unable to automatically determine the license status of this page.