| @@ -1,662 +1,662 @@ | | | @@ -1,662 +1,662 @@ |
1 | .\" $NetBSD: wait.2,v 1.39 2016/11/20 09:38:37 wiz Exp $ | | 1 | .\" $NetBSD: wait.2,v 1.40 2019/09/02 00:12:11 sevan Exp $ |
2 | .\" | | 2 | .\" |
3 | .\" Copyright (c) 1980, 1991, 1993, 1994 | | 3 | .\" Copyright (c) 1980, 1991, 1993, 1994 |
4 | .\" The Regents of the University of California. All rights reserved. | | 4 | .\" The Regents of the University of California. All rights reserved. |
5 | .\" | | 5 | .\" |
6 | .\" Redistribution and use in source and binary forms, with or without | | 6 | .\" Redistribution and use in source and binary forms, with or without |
7 | .\" modification, are permitted provided that the following conditions | | 7 | .\" modification, are permitted provided that the following conditions |
8 | .\" are met: | | 8 | .\" are met: |
9 | .\" 1. Redistributions of source code must retain the above copyright | | 9 | .\" 1. Redistributions of source code must retain the above copyright |
10 | .\" notice, this list of conditions and the following disclaimer. | | 10 | .\" notice, this list of conditions and the following disclaimer. |
11 | .\" 2. Redistributions in binary form must reproduce the above copyright | | 11 | .\" 2. Redistributions in binary form must reproduce the above copyright |
12 | .\" notice, this list of conditions and the following disclaimer in the | | 12 | .\" notice, this list of conditions and the following disclaimer in the |
13 | .\" documentation and/or other materials provided with the distribution. | | 13 | .\" documentation and/or other materials provided with the distribution. |
14 | .\" 3. Neither the name of the University nor the names of its contributors | | 14 | .\" 3. Neither the name of the University nor the names of its contributors |
15 | .\" may be used to endorse or promote products derived from this software | | 15 | .\" may be used to endorse or promote products derived from this software |
16 | .\" without specific prior written permission. | | 16 | .\" without specific prior written permission. |
17 | .\" | | 17 | .\" |
18 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | | 18 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
19 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | | 19 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
20 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | | 20 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
21 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | | 21 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
22 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | | 22 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
23 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | | 23 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
24 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | | 24 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
25 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | | 25 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
26 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 26 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
27 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 27 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
28 | .\" SUCH DAMAGE. | | 28 | .\" SUCH DAMAGE. |
29 | .\" | | 29 | .\" |
30 | .\" @(#)wait.2 8.2 (Berkeley) 4/19/94 | | 30 | .\" @(#)wait.2 8.2 (Berkeley) 4/19/94 |
31 | .\" | | 31 | .\" |
32 | .Dd November 10, 2016 | | 32 | .Dd September 2, 2019 |
33 | .Dt WAIT 2 | | 33 | .Dt WAIT 2 |
34 | .Os | | 34 | .Os |
35 | .Sh NAME | | 35 | .Sh NAME |
36 | .Nm wait , | | 36 | .Nm wait , |
37 | .Nm waitid , | | 37 | .Nm waitid , |
38 | .Nm waitpid , | | 38 | .Nm waitpid , |
39 | .Nm wait6 , | | 39 | .Nm wait6 , |
40 | .Nm wait4 , | | 40 | .Nm wait4 , |
41 | .Nm wait3 | | 41 | .Nm wait3 |
42 | .Nd wait for process termination | | 42 | .Nd wait for process termination |
43 | .Sh LIBRARY | | 43 | .Sh LIBRARY |
44 | .Lb libc | | 44 | .Lb libc |
45 | .Sh SYNOPSIS | | 45 | .Sh SYNOPSIS |
46 | .In sys/wait.h | | 46 | .In sys/wait.h |
47 | .Ft pid_t | | 47 | .Ft pid_t |
48 | .Fn wait "int *status" | | 48 | .Fn wait "int *status" |
49 | .Ft pid_t | | 49 | .Ft pid_t |
50 | .Fn waitpid "pid_t wpid" "int *status" "int options" | | 50 | .Fn waitpid "pid_t wpid" "int *status" "int options" |
51 | .Ft int | | 51 | .Ft int |
52 | .Fn waitid "idtype_t idtype" "id_t id" "siginfo_t *info" "int options" | | 52 | .Fn waitid "idtype_t idtype" "id_t id" "siginfo_t *info" "int options" |
53 | .In sys/resource.h | | 53 | .In sys/resource.h |
54 | .Ft pid_t | | 54 | .Ft pid_t |
55 | .Fn wait3 "int *status" "int options" "struct rusage *rusage" | | 55 | .Fn wait3 "int *status" "int options" "struct rusage *rusage" |
56 | .Ft pid_t | | 56 | .Ft pid_t |
57 | .Fn wait4 "pid_t wpid" "int *status" "int options" "struct rusage *rusage" | | 57 | .Fn wait4 "pid_t wpid" "int *status" "int options" "struct rusage *rusage" |
58 | .Ft pid_t | | 58 | .Ft pid_t |
59 | .Fn wait6 "idtype_t idtype" "id_t id" "int *status" "int options" "struct wrusage *wrusage" "siginfo_t *infop" | | 59 | .Fn wait6 "idtype_t idtype" "id_t id" "int *status" "int options" "struct wrusage *wrusage" "siginfo_t *infop" |
60 | .Sh DESCRIPTION | | 60 | .Sh DESCRIPTION |
61 | The | | 61 | The |
62 | .Fn wait | | 62 | .Fn wait |
63 | function suspends execution of its calling process until | | 63 | function suspends execution of its calling process until |
64 | .Fa status | | 64 | .Fa status |
65 | information is available for a terminated child process, | | 65 | information is available for a terminated child process, |
66 | or a signal is received. | | 66 | or a signal is received. |
67 | On return from a successful | | 67 | On return from a successful |
68 | .Fn wait | | 68 | .Fn wait |
69 | call, | | 69 | call, |
70 | the | | 70 | the |
71 | .Fa status | | 71 | .Fa status |
72 | area contains termination information about the process that exited | | 72 | area contains termination information about the process that exited |
73 | as defined below. | | 73 | as defined below. |
74 | .Pp | | 74 | .Pp |
75 | The | | 75 | The |
76 | .Fn wait4 | | 76 | .Fn wait4 |
77 | and | | 77 | and |
78 | .Fn wait6 | | 78 | .Fn wait6 |
79 | call provides a more general interface for programs | | 79 | call provides a more general interface for programs |
80 | that need to wait for certain child processes, | | 80 | that need to wait for certain child processes, |
81 | that need resource utilization statistics accumulated by child processes, | | 81 | that need resource utilization statistics accumulated by child processes, |
82 | or that require options. | | 82 | or that require options. |
83 | The other wait functions are implemented using | | 83 | The other wait functions are implemented using |
84 | .Fn wait4 . | | 84 | .Fn wait4 . |
85 | or | | 85 | or |
86 | .Fn wait6 . | | 86 | .Fn wait6 . |
87 | .Pp | | 87 | .Pp |
88 | The | | 88 | The |
89 | .Fn wait6 | | 89 | .Fn wait6 |
90 | function is the most general function in this family and its distinct | | 90 | function is the most general function in this family and its distinct |
91 | features are: | | 91 | features are: |
92 | .Pp | | 92 | .Pp |
93 | All of the desired process statuses to be waited on must be explicitly | | 93 | All of the desired process statuses to be waited on must be explicitly |
94 | specified in | | 94 | specified in |
95 | .Fa options . | | 95 | .Fa options . |
96 | The | | 96 | The |
97 | .Fn wait , | | 97 | .Fn wait , |
98 | .Fn waitpid , | | 98 | .Fn waitpid , |
99 | .Fn wait3 , | | 99 | .Fn wait3 , |
100 | and | | 100 | and |
101 | .Fn wait4 | | 101 | .Fn wait4 |
102 | functions all implicitly wait for exited and trapped processes, | | 102 | functions all implicitly wait for exited and trapped processes, |
103 | but the | | 103 | but the |
104 | .Fn waitid | | 104 | .Fn waitid |
105 | and | | 105 | and |
106 | .Fn wait6 | | 106 | .Fn wait6 |
107 | functions require the corresponding | | 107 | functions require the corresponding |
108 | .Dv WEXITED | | 108 | .Dv WEXITED |
109 | and | | 109 | and |
110 | .Dv WTRAPPED | | 110 | .Dv WTRAPPED |
111 | flags to be explicitly specified. | | 111 | flags to be explicitly specified. |
112 | This allows waiting for processes which have experienced other | | 112 | This allows waiting for processes which have experienced other |
113 | status changes without having to also handle the exit status from | | 113 | status changes without having to also handle the exit status from |
114 | terminated processes. | | 114 | terminated processes. |
115 | .Pp | | 115 | .Pp |
116 | The | | 116 | The |
117 | .Fn wait6 | | 117 | .Fn wait6 |
118 | function accepts a | | 118 | function accepts a |
119 | .Fa wrusage | | 119 | .Fa wrusage |
120 | argument which points to a structure defined as: | | 120 | argument which points to a structure defined as: |
121 | .Bd -literal | | 121 | .Bd -literal |
122 | struct wrusage { | | 122 | struct wrusage { |
123 | struct rusage wru_self; | | 123 | struct rusage wru_self; |
124 | struct rusage wru_children; | | 124 | struct rusage wru_children; |
125 | }; | | 125 | }; |
126 | .Ed | | 126 | .Ed |
127 | .Pp | | 127 | .Pp |
128 | This allows the calling process to collect resource usage statistics | | 128 | This allows the calling process to collect resource usage statistics |
129 | from both its own child process as well as from its grand children. | | 129 | from both its own child process as well as from its grand children. |
130 | When no resource usage statistics are needed this pointer can be | | 130 | When no resource usage statistics are needed this pointer can be |
131 | .Dv NULL . | | 131 | .Dv NULL . |
132 | .Pp | | 132 | .Pp |
133 | The last argument | | 133 | The last argument |
134 | .Fa infop | | 134 | .Fa infop |
135 | must be either | | 135 | must be either |
136 | .Dv NULL | | 136 | .Dv NULL |
137 | or a pointer to a | | 137 | or a pointer to a |
138 | .Fa siginfo_t | | 138 | .Fa siginfo_t |
139 | structure. | | 139 | structure. |
140 | If | | 140 | If |
141 | .Pf non- Dv NULL , | | 141 | .Pf non- Dv NULL , |
142 | the structure is filled with the same data as for a | | 142 | the structure is filled with the same data as for a |
143 | .Dv SIGCHLD | | 143 | .Dv SIGCHLD |
144 | signal delivered when the process changed state. | | 144 | signal delivered when the process changed state. |
145 | .Pp | | 145 | .Pp |
146 | The set of child processes to be queried is specified by the arguments | | 146 | The set of child processes to be queried is specified by the arguments |
147 | .Fa idtype | | 147 | .Fa idtype |
148 | and | | 148 | and |
149 | .Fa id . | | 149 | .Fa id . |
150 | The separate | | 150 | The separate |
151 | .Fa idtype | | 151 | .Fa idtype |
152 | and | | 152 | and |
153 | .Fa id | | 153 | .Fa id |
154 | arguments support many other types of | | 154 | arguments support many other types of |
155 | identifiers in addition to process IDs and process group IDs. | | 155 | identifiers in addition to process IDs and process group IDs. |
156 | .Bl -bullet -offset indent | | 156 | .Bl -bullet -offset indent |
157 | .It | | 157 | .It |
158 | If | | 158 | If |
159 | .Fa idtype | | 159 | .Fa idtype |
160 | is | | 160 | is |
161 | .Dv P_PID , | | 161 | .Dv P_PID , |
162 | .Fn waitid | | 162 | .Fn waitid |
163 | and | | 163 | and |
164 | .Fn wait6 | | 164 | .Fn wait6 |
165 | wait for the child process with a process ID equal to | | 165 | wait for the child process with a process ID equal to |
166 | .Dv (pid_t)id . | | 166 | .Dv (pid_t)id . |
167 | .It | | 167 | .It |
168 | If | | 168 | If |
169 | .Fa idtype | | 169 | .Fa idtype |
170 | is | | 170 | is |
171 | .Dv P_PGID , | | 171 | .Dv P_PGID , |
172 | .Fn waitid | | 172 | .Fn waitid |
173 | and | | 173 | and |
174 | .Fn wait6 | | 174 | .Fn wait6 |
175 | wait for the child process with a process group ID equal to | | 175 | wait for the child process with a process group ID equal to |
176 | .Dv (pid_t)id . | | 176 | .Dv (pid_t)id . |
177 | .It | | 177 | .It |
178 | If | | 178 | If |
179 | .Fa idtype | | 179 | .Fa idtype |
180 | is | | 180 | is |
181 | .Dv P_ALL , | | 181 | .Dv P_ALL , |
182 | .Fn waitid | | 182 | .Fn waitid |
183 | and | | 183 | and |
184 | .Fn wait6 | | 184 | .Fn wait6 |
185 | wait for any child process and the | | 185 | wait for any child process and the |
186 | .Dv id | | 186 | .Dv id |
187 | is ignored. | | 187 | is ignored. |
188 | .It | | 188 | .It |
189 | If | | 189 | If |
190 | .Fa idtype | | 190 | .Fa idtype |
191 | is | | 191 | is |
192 | .Dv P_PID | | 192 | .Dv P_PID |
193 | or | | 193 | or |
194 | .Dv P_PGID | | 194 | .Dv P_PGID |
195 | and the | | 195 | and the |
196 | .Dv id | | 196 | .Dv id |
197 | is zero, | | 197 | is zero, |
198 | .Fn waitid | | 198 | .Fn waitid |
199 | and | | 199 | and |
200 | .Fn wait6 | | 200 | .Fn wait6 |
201 | wait for any child process in the same process group as the caller. | | 201 | wait for any child process in the same process group as the caller. |
202 | .El | | 202 | .El |
203 | .Pp | | 203 | .Pp |
204 | Non-standard identifier types supported by this | | 204 | Non-standard identifier types supported by this |
205 | implementation of | | 205 | implementation of |
206 | .Fn waitid | | 206 | .Fn waitid |
207 | and | | 207 | and |
208 | .Fn wait6 | | 208 | .Fn wait6 |
209 | are: | | 209 | are: |
210 | .Bl -tag -width P_JAILID | | 210 | .Bl -tag -width P_JAILID |
211 | .It Dv P_UID | | 211 | .It Dv P_UID |
212 | Wait for processes whose effective user ID is equal to | | 212 | Wait for processes whose effective user ID is equal to |
213 | .Dv (uid_t) Fa id . | | 213 | .Dv (uid_t) Fa id . |
214 | .It Dv P_GID | | 214 | .It Dv P_GID |
215 | Wait for processes whose effective group ID is equal to | | 215 | Wait for processes whose effective group ID is equal to |
216 | .Dv (gid_t) Fa id . | | 216 | .Dv (gid_t) Fa id . |
217 | .It Dv P_SID | | 217 | .It Dv P_SID |
218 | Wait for processes whose session ID is equal to | | 218 | Wait for processes whose session ID is equal to |
219 | .Fa id . | | 219 | .Fa id . |
220 | .\" This is just how sessions work, not sure this needs to be documented here | | 220 | .\" This is just how sessions work, not sure this needs to be documented here |
221 | If the child process started its own session, | | 221 | If the child process started its own session, |
222 | its session ID will be the same as its process ID. | | 222 | its session ID will be the same as its process ID. |
223 | Otherwise the session ID of a child process will match the caller's session ID. | | 223 | Otherwise the session ID of a child process will match the caller's session ID. |
224 | .\" .It Dv P_JAILID | | 224 | .\" .It Dv P_JAILID |
225 | .\" Waits for processes within a jail whose jail identifier is equal to | | 225 | .\" Waits for processes within a jail whose jail identifier is equal to |
226 | .\" .Fa id . | | 226 | .\" .Fa id . |
227 | .El | | 227 | .El |
228 | .Pp | | 228 | .Pp |
229 | For the | | 229 | For the |
230 | .Fn waitpid | | 230 | .Fn waitpid |
231 | and | | 231 | and |
232 | .Fn wait4 | | 232 | .Fn wait4 |
233 | functions, the single | | 233 | functions, the single |
234 | .Fa wpid | | 234 | .Fa wpid |
235 | argument specifies the set of child processes for which to wait. | | 235 | argument specifies the set of child processes for which to wait. |
236 | The following symbolic constants are defined in | | 236 | The following symbolic constants are defined in |
237 | .In sys/wait.h | | 237 | .In sys/wait.h |
238 | .Bd -literal -offset indent | | 238 | .Bd -literal -offset indent |
239 | #define WAIT_ANY (-1) /* any process */ | | 239 | #define WAIT_ANY (-1) /* any process */ |
240 | #define WAIT_MYPGRP 0 /* any process in my process group */ | | 240 | #define WAIT_MYPGRP 0 /* any process in my process group */ |
241 | .Ed | | 241 | .Ed |
242 | .Bl -bullet -offset indent | | 242 | .Bl -bullet -offset indent |
243 | .It | | 243 | .It |
244 | If | | 244 | If |
245 | .Fa wpid | | 245 | .Fa wpid |
246 | is | | 246 | is |
247 | .Dv WAIT_ANY , | | 247 | .Dv WAIT_ANY , |
248 | the call waits for any child process. | | 248 | the call waits for any child process. |
249 | .It | | 249 | .It |
250 | If | | 250 | If |
251 | .Fa wpid | | 251 | .Fa wpid |
252 | is | | 252 | is |
253 | .Dv WAIT_MYPGRP , | | 253 | .Dv WAIT_MYPGRP , |
254 | the call waits for any child process in the process group of the caller. | | 254 | the call waits for any child process in the process group of the caller. |
255 | .It | | 255 | .It |
256 | If | | 256 | If |
257 | .Fa wpid | | 257 | .Fa wpid |
258 | is greater than zero, the call waits for the process with process ID | | 258 | is greater than zero, the call waits for the process with process ID |
259 | .Fa wpid . | | 259 | .Fa wpid . |
260 | .It | | 260 | .It |
261 | If | | 261 | If |
262 | .Fa wpid | | 262 | .Fa wpid |
263 | is less than \-1, the call waits for any process whose process group ID | | 263 | is less than \-1, the call waits for any process whose process group ID |
264 | equals the absolute value of | | 264 | equals the absolute value of |
265 | .Fa wpid . | | 265 | .Fa wpid . |
266 | .El | | 266 | .El |
267 | .Pp | | 267 | .Pp |
268 | The | | 268 | The |
269 | .Fa status | | 269 | .Fa status |
270 | argument is defined below. | | 270 | argument is defined below. |
271 | .Pp | | 271 | .Pp |
272 | The | | 272 | The |
273 | .Fa options | | 273 | .Fa options |
274 | argument contains the bitwise OR of any of the following options. | | 274 | argument contains the bitwise OR of any of the following options. |
275 | .Bl -tag -width WCONTINUED | | 275 | .Bl -tag -width WCONTINUED |
276 | .It Dv WALLSIG | | 276 | .It Dv WALLSIG |
277 | If this option is specified, the call will wait for all children regardless | | 277 | If this option is specified, the call will wait for all children regardless |
278 | of what exit signal they post. | | 278 | of what exit signal they post. |
279 | .It Dv WALTSIG | | 279 | .It Dv WALTSIG |
280 | If this option is specified, the call will wait only for processes that | | 280 | If this option is specified, the call will wait only for processes that |
281 | are configured to post a signal other than | | 281 | are configured to post a signal other than |
282 | .Dv SIGCHLD | | 282 | .Dv SIGCHLD |
283 | when they exit. | | 283 | when they exit. |
284 | If | | 284 | If |
285 | .Dv WALTSIG | | 285 | .Dv WALTSIG |
286 | is not specified, the call will wait only for processes that | | 286 | is not specified, the call will wait only for processes that |
287 | are configured to post | | 287 | are configured to post |
288 | .Dv SIGCHLD . | | 288 | .Dv SIGCHLD . |
289 | .It Dv WCONTINUED | | 289 | .It Dv WCONTINUED |
290 | Report the status of selected processes that | | 290 | Report the status of selected processes that |
291 | have continued from a job control stop by receiving a | | 291 | have continued from a job control stop by receiving a |
292 | .Dv SIGCONT | | 292 | .Dv SIGCONT |
293 | signal. | | 293 | signal. |
294 | .It Dv WEXITED | | 294 | .It Dv WEXITED |
295 | Report the status of selected processes which have terminated. | | 295 | Report the status of selected processes which have terminated. |
296 | This flag is implicitly set for the functions | | 296 | This flag is implicitly set for the functions |
297 | .Fn wait , | | 297 | .Fn wait , |
298 | .Fn waitpid , | | 298 | .Fn waitpid , |
299 | .Fn wait3 , | | 299 | .Fn wait3 , |
300 | and | | 300 | and |
301 | .Fn wait4 . | | 301 | .Fn wait4 . |
302 | .br | | 302 | .br |
303 | For the | | 303 | For the |
304 | .Fn waitid | | 304 | .Fn waitid |
305 | and | | 305 | and |
306 | .Fn wait6 | | 306 | .Fn wait6 |
307 | functions, the flag has to be explicitly included in | | 307 | functions, the flag has to be explicitly included in |
308 | .Fa options | | 308 | .Fa options |
309 | if status reports from terminated processes are expected. | | 309 | if status reports from terminated processes are expected. |
310 | .It Dv WNOHANG | | 310 | .It Dv WNOHANG |
311 | Do not block when | | 311 | Do not block when |
312 | there are no processes wishing to report status. | | 312 | there are no processes wishing to report status. |
313 | .It Dv WNOWAIT | | 313 | .It Dv WNOWAIT |
314 | Keep the process whose status is returned in a waitable state. | | 314 | Keep the process whose status is returned in a waitable state. |
315 | The process may be waited for again after this call completes. | | 315 | The process may be waited for again after this call completes. |
316 | .It Dv WNOZOMBIE | | 316 | .It Dv WNOZOMBIE |
317 | Exclude zombie processes from the child selection criteria. | | 317 | Exclude zombie processes from the child selection criteria. |
318 | .It Dv WSTOPPED | | 318 | .It Dv WSTOPPED |
319 | An alias for | | 319 | An alias for |
320 | .Dv WUNTRACED . | | 320 | .Dv WUNTRACED . |
321 | .It Dv WTRAPPED | | 321 | .It Dv WTRAPPED |
322 | Report the status of selected processes which are being traced via | | 322 | Report the status of selected processes which are being traced via |
323 | .Xr ptrace 2 | | 323 | .Xr ptrace 2 |
324 | and have trapped or reached a breakpoint. | | 324 | and have trapped or reached a breakpoint. |
325 | This flag is implicitly set for the functions | | 325 | This flag is implicitly set for the functions |
326 | .Fn wait , | | 326 | .Fn wait , |
327 | .Fn waitpid , | | 327 | .Fn waitpid , |
328 | .Fn wait3 , | | 328 | .Fn wait3 , |
329 | and | | 329 | and |
330 | .Fn wait4 . | | 330 | .Fn wait4 . |
331 | .br | | 331 | .br |
332 | For the | | 332 | For the |
333 | .Fn waitid | | 333 | .Fn waitid |
334 | and | | 334 | and |
335 | .Fn wait6 | | 335 | .Fn wait6 |
336 | functions, the flag has to be explicitly included in | | 336 | functions, the flag has to be explicitly included in |
337 | .Fa options | | 337 | .Fa options |
338 | if status reports from trapped processes are expected. | | 338 | if status reports from trapped processes are expected. |
339 | .It Dv WUNTRACED | | 339 | .It Dv WUNTRACED |
340 | Report the status of selected processes which are stopped due to a | | 340 | Report the status of selected processes which are stopped due to a |
341 | .Dv SIGTTIN , SIGTTOU , SIGTSTP , | | 341 | .Dv SIGTTIN , SIGTTOU , SIGTSTP , |
342 | or | | 342 | or |
343 | .Dv SIGSTOP | | 343 | .Dv SIGSTOP |
344 | signal. | | 344 | signal. |
345 | .It Dv __WALL | | 345 | .It Dv __WALL |
346 | This is an alias for | | 346 | This is an alias for |
347 | .Dv WALLSIG . | | 347 | .Dv WALLSIG . |
348 | It is provided for compatibility with the Linux | | 348 | It is provided for compatibility with the Linux |
349 | .Xr clone 2 | | 349 | .Xr clone 2 |
350 | API . | | 350 | API . |
351 | .It Dv __WCLONE | | 351 | .It Dv __WCLONE |
352 | This is an alias for | | 352 | This is an alias for |
353 | .Dv WALTSIG . | | 353 | .Dv WALTSIG . |
354 | It is provided for compatibility with the Linux | | 354 | It is provided for compatibility with the Linux |
355 | .Xr clone 2 | | 355 | .Xr clone 2 |
356 | API. | | 356 | API. |
357 | .El | | 357 | .El |
358 | .sp | | 358 | .sp |
359 | For the | | 359 | For the |
360 | .Fn waitid | | 360 | .Fn waitid |
361 | and | | 361 | and |
362 | .Fn wait6 | | 362 | .Fn wait6 |
363 | functions, at least one of the options | | 363 | functions, at least one of the options |
364 | .Dv WEXITED , | | 364 | .Dv WEXITED , |
365 | .Dv WUNTRACED , | | 365 | .Dv WUNTRACED , |
366 | .Dv WSTOPPED , | | 366 | .Dv WSTOPPED , |
367 | .Dv WTRAPPED , | | 367 | .Dv WTRAPPED , |
368 | or | | 368 | or |
369 | .Dv WCONTINUED | | 369 | .Dv WCONTINUED |
370 | must be specified. | | 370 | must be specified. |
371 | Otherwise there will be no events for the call to report. | | 371 | Otherwise there will be no events for the call to report. |
372 | To avoid hanging indefinitely in such a case these functions | | 372 | To avoid hanging indefinitely in such a case these functions |
373 | return \-1 with | | 373 | return \-1 with |
374 | .Dv errno | | 374 | .Dv errno |
375 | set to | | 375 | set to |
376 | .Dv EINVAL . | | 376 | .Dv EINVAL . |
377 | .Pp | | 377 | .Pp |
378 | If | | 378 | If |
379 | .Fa rusage | | 379 | .Fa rusage |
380 | is | | 380 | is |
381 | .Pf non- Dv NULL , | | 381 | .Pf non- Dv NULL , |
382 | a summary of the resources used by the terminated | | 382 | a summary of the resources used by the terminated |
383 | process and all its children is returned. | | 383 | process and all its children is returned. |
384 | .Pp | | 384 | .Pp |
385 | If | | 385 | If |
386 | .Fa wrusage | | 386 | .Fa wrusage |
387 | is | | 387 | is |
388 | .Pf non- Dv NULL , | | 388 | .Pf non- Dv NULL , |
389 | separate summaries are returned for the resources used | | 389 | separate summaries are returned for the resources used |
390 | by the terminated process and the resources used by all its children. | | 390 | by the terminated process and the resources used by all its children. |
391 | .Pp | | 391 | .Pp |
392 | If | | 392 | If |
393 | .Fa infop | | 393 | .Fa infop |
394 | is | | 394 | is |
395 | .Pf non- Dv NULL , | | 395 | .Pf non- Dv NULL , |
396 | a | | 396 | a |
397 | .Dv siginfo_t | | 397 | .Dv siginfo_t |
398 | structure is returned with the | | 398 | structure is returned with the |
399 | .Fa si_signo | | 399 | .Fa si_signo |
400 | field set to | | 400 | field set to |
401 | .Dv SIGCHLD | | 401 | .Dv SIGCHLD |
402 | and the | | 402 | and the |
403 | .Fa si_pid | | 403 | .Fa si_pid |
404 | field set to the process ID of the process reporting status. | | 404 | field set to the process ID of the process reporting status. |
405 | For the exited process, the | | 405 | For the exited process, the |
406 | .Fa si_status | | 406 | .Fa si_status |
407 | field of the | | 407 | field of the |
408 | .Dv siginfo_t | | 408 | .Dv siginfo_t |
409 | structure contains the full 32 bit exit status passed to | | 409 | structure contains the full 32 bit exit status passed to |
410 | .Xr _exit 2 ; | | 410 | .Xr _exit 2 ; |
411 | the | | 411 | the |
412 | .Fa status | | 412 | .Fa status |
413 | argument of other calls only returns 8 lowest bits of the exit status. | | 413 | argument of other calls only returns 8 lowest bits of the exit status. |
414 | .Pp | | 414 | .Pp |
415 | When the | | 415 | When the |
416 | .Dv WNOHANG | | 416 | .Dv WNOHANG |
417 | option is specified and no processes | | 417 | option is specified and no processes |
418 | wish to report status, | | 418 | wish to report status, |
419 | .Fn waitid | | 419 | .Fn waitid |
420 | sets the | | 420 | sets the |
421 | .Fa si_signo | | 421 | .Fa si_signo |
422 | and | | 422 | and |
423 | .Fa si_pid | | 423 | .Fa si_pid |
424 | fields in | | 424 | fields in |
425 | .Fa infop | | 425 | .Fa infop |
426 | to zero. | | 426 | to zero. |
427 | Checking these fields is the only way to know if a status change was reported. | | 427 | Checking these fields is the only way to know if a status change was reported. |
428 | .Pp | | 428 | .Pp |
429 | When the | | 429 | When the |
430 | .Dv WNOHANG | | 430 | .Dv WNOHANG |
431 | option is specified and no processes | | 431 | option is specified and no processes |
432 | wish to report status, | | 432 | wish to report status, |
433 | .Fn wait4 | | 433 | .Fn wait4 |
434 | returns a | | 434 | returns a |
435 | process id | | 435 | process id |
436 | of 0. | | 436 | of 0. |
437 | .Pp | | 437 | .Pp |
438 | The | | 438 | The |
439 | .Fn waitpid | | 439 | .Fn waitpid |
440 | call is identical to | | 440 | call is identical to |
441 | .Fn wait4 | | 441 | .Fn wait4 |
442 | with an | | 442 | with an |
443 | .Fa rusage | | 443 | .Fa rusage |
444 | value of zero. | | 444 | value of zero. |
445 | The older | | 445 | The older |
446 | .Fn wait3 | | 446 | .Fn wait3 |
447 | call is the same as | | 447 | call is the same as |
448 | .Fn wait4 | | 448 | .Fn wait4 |
449 | with a | | 449 | with a |
450 | .Fa wpid | | 450 | .Fa wpid |
451 | value of \-1. | | 451 | value of \-1. |
452 | .Pp | | 452 | .Pp |
453 | The following macros may be used to test the manner of exit of the process. | | 453 | The following macros may be used to test the manner of exit of the process. |
454 | Note that these macros expect the | | 454 | Note that these macros expect the |
455 | .Fa status | | 455 | .Fa status |
456 | value itself, not a pointer to the | | 456 | value itself, not a pointer to the |
457 | .Fa status | | 457 | .Fa status |
458 | value. | | 458 | value. |
459 | One of the first three macros will evaluate to a non-zero (true) value: | | 459 | One of the first three macros will evaluate to a non-zero (true) value: |
460 | .Bl -tag -width Ds | | 460 | .Bl -tag -width Ds |
461 | .It Fn WIFEXITED status | | 461 | .It Fn WIFEXITED status |
462 | True if the process terminated normally by a call to | | 462 | True if the process terminated normally by a call to |
463 | .Xr _exit 2 | | 463 | .Xr _exit 2 |
464 | or | | 464 | or |
465 | .Xr exit 3 . | | 465 | .Xr exit 3 . |
466 | .It Fn WIFSIGNALED status | | 466 | .It Fn WIFSIGNALED status |
467 | True if the process terminated due to receipt of a signal. | | 467 | True if the process terminated due to receipt of a signal. |
468 | .It Fn WIFSTOPPED status | | 468 | .It Fn WIFSTOPPED status |
469 | True if the process has not terminated, but has stopped and can be restarted. | | 469 | True if the process has not terminated, but has stopped and can be restarted. |
470 | This macro can be true only if the wait call specified the | | 470 | This macro can be true only if the wait call specified the |
471 | .Dv WUNTRACED | | 471 | .Dv WUNTRACED |
472 | option | | 472 | option |
473 | or if the child process is being traced (see | | 473 | or if the child process is being traced (see |
474 | .Xr ptrace 2 ) . | | 474 | .Xr ptrace 2 ) . |
475 | .It Fn WIFCONTINUED status | | 475 | .It Fn WIFCONTINUED status |
476 | True if the process has not terminated, but has been continued via the | | 476 | True if the process has not terminated, but has been continued via the |
477 | delivery of the | | 477 | delivery of the |
478 | .Dv SIGCONT | | 478 | .Dv SIGCONT |
479 | signal. | | 479 | signal. |
480 | This macro can be true only if the wait call specified the | | 480 | This macro can be true only if the wait call specified the |
481 | .Dv WCONTINUED | | 481 | .Dv WCONTINUED |
482 | option. | | 482 | option. |
483 | .El | | 483 | .El |
484 | .Pp | | 484 | .Pp |
485 | Depending on the values of those macros, the following macros | | 485 | Depending on the values of those macros, the following macros |
486 | produce the remaining status information about the child process: | | 486 | produce the remaining status information about the child process: |
487 | .Bl -tag -width Ds | | 487 | .Bl -tag -width Ds |
488 | .It Fn WEXITSTATUS status | | 488 | .It Fn WEXITSTATUS status |
489 | If | | 489 | If |
490 | .Fn WIFEXITED status | | 490 | .Fn WIFEXITED status |
491 | is true, evaluates to the low-order 8 bits | | 491 | is true, evaluates to the low-order 8 bits |
492 | of the argument passed to | | 492 | of the argument passed to |
493 | .Xr _exit 2 | | 493 | .Xr _exit 2 |
494 | or | | 494 | or |
495 | .Xr exit 3 | | 495 | .Xr exit 3 |
496 | by the child. | | 496 | by the child. |
497 | .It Fn WTERMSIG status | | 497 | .It Fn WTERMSIG status |
498 | If | | 498 | If |
499 | .Fn WIFSIGNALED status | | 499 | .Fn WIFSIGNALED status |
500 | is true, evaluates to the number of the signal | | 500 | is true, evaluates to the number of the signal |
501 | that caused the termination of the process. | | 501 | that caused the termination of the process. |
502 | .It Fn WCOREDUMP status | | 502 | .It Fn WCOREDUMP status |
503 | If | | 503 | If |
504 | .Fn WIFSIGNALED status | | 504 | .Fn WIFSIGNALED status |
505 | is true, evaluates as true if the termination | | 505 | is true, evaluates as true if the termination |
506 | of the process was accompanied by the creation of a core file | | 506 | of the process was accompanied by the creation of a core file |
507 | containing an image of the process when the signal was received. | | 507 | containing an image of the process when the signal was received. |
508 | .It Fn WSTOPSIG status | | 508 | .It Fn WSTOPSIG status |
509 | If | | 509 | If |
510 | .Fn WIFSTOPPED status | | 510 | .Fn WIFSTOPPED status |
511 | is true, evaluates to the number of the signal | | 511 | is true, evaluates to the number of the signal |
512 | that caused the process to stop. | | 512 | that caused the process to stop. |
513 | .El | | 513 | .El |
514 | .Sh NOTES | | 514 | .Sh NOTES |
515 | See | | 515 | See |
516 | .Xr sigaction 2 | | 516 | .Xr sigaction 2 |
517 | for a list of termination signals. | | 517 | for a list of termination signals. |
518 | A status of 0 indicates normal termination. | | 518 | A status of 0 indicates normal termination. |
519 | .Pp | | 519 | .Pp |
520 | If a parent process terminates without | | 520 | If a parent process terminates without |
521 | waiting for all of its child processes to terminate, | | 521 | waiting for all of its child processes to terminate, |
522 | the remaining child processes are assigned the parent | | 522 | the remaining child processes are assigned the parent |
523 | process 1 ID (the init process ID). | | 523 | process 1 ID (the init process ID). |
524 | .Pp | | 524 | .Pp |
525 | If a signal is caught while any of the | | 525 | If a signal is caught while any of the |
526 | .Fn wait | | 526 | .Fn wait |
527 | calls is pending, | | 527 | calls is pending, |
528 | the call may be interrupted or restarted when the signal-catching routine | | 528 | the call may be interrupted or restarted when the signal-catching routine |
529 | returns, | | 529 | returns, |
530 | depending on the options in effect for the signal; | | 530 | depending on the options in effect for the signal; |
531 | see | | 531 | see |
532 | .Xr siginterrupt 3 . | | 532 | .Xr siginterrupt 3 . |
533 | .Sh RETURN VALUES | | 533 | .Sh RETURN VALUES |
534 | If | | 534 | If |
535 | .Fn wait | | 535 | .Fn wait |
536 | returns due to a stopped | | 536 | returns due to a stopped |
537 | or terminated child process, the process ID of the child | | 537 | or terminated child process, the process ID of the child |
538 | is returned to the calling process. | | 538 | is returned to the calling process. |
539 | Otherwise, a value of \-1 is returned and | | 539 | Otherwise, a value of \-1 is returned and |
540 | .Va errno | | 540 | .Va errno |
541 | is set to indicate the error. | | 541 | is set to indicate the error. |
542 | .Pp | | 542 | .Pp |
543 | If | | 543 | If |
544 | .Fn wait6 , | | 544 | .Fn wait6 , |
545 | .Fn wait4 , | | 545 | .Fn wait4 , |
546 | .Fn wait3 | | 546 | .Fn wait3 |
547 | or | | 547 | or |
548 | .Fn waitpid | | 548 | .Fn waitpid |
549 | returns due to a stopped | | 549 | returns due to a stopped |
550 | or terminated child process, the process ID of the child | | 550 | or terminated child process, the process ID of the child |
551 | is returned to the calling process. | | 551 | is returned to the calling process. |
552 | If there are no children not previously awaited, | | 552 | If there are no children not previously awaited, |
553 | \-1 is returned with | | 553 | \-1 is returned with |
554 | .Va errno | | 554 | .Va errno |
555 | set to | | 555 | set to |
556 | .Bq Er ECHILD . | | 556 | .Bq Er ECHILD . |
557 | Otherwise, if | | 557 | Otherwise, if |
558 | .Dv WNOHANG | | 558 | .Dv WNOHANG |
559 | is specified and there are | | 559 | is specified and there are |
560 | no stopped or exited children, 0 is returned. | | 560 | no stopped or exited children, 0 is returned. |
561 | If an error is detected or a caught signal aborts the call, | | 561 | If an error is detected or a caught signal aborts the call, |
562 | a value of \-1 is returned and | | 562 | a value of \-1 is returned and |
563 | .Va errno | | 563 | .Va errno |
564 | is set to indicate the error. | | 564 | is set to indicate the error. |
565 | .Pp | | 565 | .Pp |
566 | If | | 566 | If |
567 | .Fn waitid | | 567 | .Fn waitid |
568 | returns because one or more processes have a state change to report, | | 568 | returns because one or more processes have a state change to report, |
569 | 0 is returned. | | 569 | 0 is returned. |
570 | If an error is detected, | | 570 | If an error is detected, |
571 | a value of -1 | | 571 | a value of -1 |
572 | is returned and | | 572 | is returned and |
573 | .Va errno | | 573 | .Va errno |
574 | is set to indicate the error. | | 574 | is set to indicate the error. |
575 | If | | 575 | If |
576 | .Dv WNOHANG | | 576 | .Dv WNOHANG |
577 | is specified and there are | | 577 | is specified and there are |
578 | no stopped, continued or exited children, | | 578 | no stopped, continued or exited children, |
579 | 0 is returned. | | 579 | 0 is returned. |
580 | The | | 580 | The |
581 | .Fa si_signo | | 581 | .Fa si_signo |
582 | and | | 582 | and |
583 | .Fa si_pid | | 583 | .Fa si_pid |
584 | fields of | | 584 | fields of |
585 | .Fa infop | | 585 | .Fa infop |
586 | must be checked against zero to determine if a process reported status. | | 586 | must be checked against zero to determine if a process reported status. |
587 | .Sh ERRORS | | 587 | .Sh ERRORS |
588 | .Fn wait | | 588 | .Fn wait |
589 | will fail and return immediately if: | | 589 | will fail and return immediately if: |
590 | .Bl -tag -width Er | | 590 | .Bl -tag -width Er |
591 | .It Bq Er ECHILD | | 591 | .It Bq Er ECHILD |
592 | The calling process has no existing unwaited-for child processes; or | | 592 | The calling process has no existing unwaited-for child processes; or |
593 | no status from the terminated child process is available | | 593 | no status from the terminated child process is available |
594 | because the calling process has asked the system to discard | | 594 | because the calling process has asked the system to discard |
595 | such status by ignoring the signal | | 595 | such status by ignoring the signal |
596 | .Dv SIGCHLD | | 596 | .Dv SIGCHLD |
597 | or setting the flag | | 597 | or setting the flag |
598 | .Dv SA_NOCLDWAIT | | 598 | .Dv SA_NOCLDWAIT |
599 | for that signal. | | 599 | for that signal. |
600 | .It Bq Er EFAULT | | 600 | .It Bq Er EFAULT |
601 | The | | 601 | The |
602 | .Fa status | | 602 | .Fa status |
603 | or | | 603 | or |
604 | .Fa rusage | | 604 | .Fa rusage |
605 | arguments point to an illegal address. | | 605 | arguments point to an illegal address. |
606 | (May not be detected before exit of a child process.) | | 606 | (May not be detected before exit of a child process.) |
607 | .It Bq Er EINTR | | 607 | .It Bq Er EINTR |
608 | The call was interrupted by a caught signal, | | 608 | The call was interrupted by a caught signal, |
609 | or the signal did not have the | | 609 | or the signal did not have the |
610 | .Dv SA_RESTART | | 610 | .Dv SA_RESTART |
611 | flag set. | | 611 | flag set. |
612 | .El | | 612 | .El |
613 | .Pp | | 613 | .Pp |
614 | In addition, | | 614 | In addition, |
615 | .Fn wait6 , | | 615 | .Fn wait6 , |
616 | .Fn wait3 , | | 616 | .Fn wait3 , |
617 | .Fn wait4 , | | 617 | .Fn wait4 , |
618 | .Fn waitid , | | 618 | .Fn waitid , |
619 | and | | 619 | and |
620 | .Fn waitpid | | 620 | .Fn waitpid |
621 | will fail and return immediately if: | | 621 | will fail and return immediately if: |
622 | .Bl -tag -width Er | | 622 | .Bl -tag -width Er |
623 | .It Bq Er EINVAL | | 623 | .It Bq Er EINVAL |
624 | An invalid value was specified for | | 624 | An invalid value was specified for |
625 | .Fa options . | | 625 | .Fa options . |
626 | .El | | 626 | .El |
627 | .Sh SEE ALSO | | 627 | .Sh SEE ALSO |
628 | .Xr _exit 2 , | | 628 | .Xr _exit 2 , |
629 | .Xr fork 2 , | | 629 | .Xr fork 2 , |
630 | .Xr ptrace 2 , | | 630 | .Xr ptrace 2 , |
631 | .Xr sigaction 2 , | | 631 | .Xr sigaction 2 , |
632 | .Xr siginfo 2 , | | 632 | .Xr siginfo 2 , |
633 | .Xr exit 3 , | | 633 | .Xr exit 3 , |
634 | .Xr siginterrupt 3 | | 634 | .Xr siginterrupt 3 |
635 | .Sh STANDARDS | | 635 | .Sh STANDARDS |
636 | The | | 636 | The |
637 | .Fn wait | | 637 | .Fn wait |
638 | and | | 638 | and |
639 | .Fn waitpid | | 639 | .Fn waitpid |
640 | functions conform to | | 640 | functions conform to |
641 | .St -p1003.1-90 ; | | 641 | .St -p1003.1-90 ; |
642 | the | | 642 | the |
643 | .Fn waitid | | 643 | .Fn waitid |
644 | function conforms to | | 644 | function conforms to |
645 | .St -p1003.1-2004 ; | | 645 | .St -p1003.1-2004 ; |
646 | the | | 646 | the |
647 | .Fn wait3 | | 647 | .Fn wait3 |
648 | function conforms to | | 648 | function conforms to |
649 | .St -xpg4 ; | | 649 | .St -xpg4 ; |
650 | .Fn wait4 | | 650 | .Fn wait4 |
651 | is an extension. | | 651 | is an extension. |
652 | The | | 652 | The |
653 | .Fn WCOREDUMP | | 653 | .Fn WCOREDUMP |
654 | macro | | 654 | macro |
655 | and the ability to restart a pending | | 655 | and the ability to restart a pending |
656 | .Fn wait | | 656 | .Fn wait |
657 | call are extensions to the POSIX interface. | | 657 | call are extensions to the POSIX interface. |
658 | .Sh HISTORY | | 658 | .Sh HISTORY |
659 | A | | 659 | A |
660 | .Fn wait | | 660 | .Fn wait |
661 | function call appeared in | | 661 | function call appeared in |
662 | .At v2 . | | 662 | .At v1 . |