28 .\" Common Development and Distribution License (the "License").
29 .\" You may not use this file except in compliance with the License.
30 .\"
31 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
32 .\" or http://www.opensolaris.org/os/licensing.
33 .\" See the License for the specific language governing permissions
34 .\" and limitations under the License.
35 .\"
36 .\" When distributing Covered Code, include this CDDL HEADER in each
37 .\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
38 .\" If applicable, add the following below this CDDL HEADER, with the
39 .\" fields enclosed by brackets "[]" replaced with your own identifying
40 .\" information: Portions Copyright [yyyy] [name of copyright owner]
41 .\"
42 .\"
43 .\" Copyright 1989 AT&T
44 .\" Copyright 1992 X/Open Company Limited
45 .\" Portions Copyright (c) 1982-2007 AT&T Knowledge Ventures
46 .\" Copyright (c) 2008, Sun Microsystems, Inc. All Rights Reserved
47 .\"
48 .TH WAIT 1 "Mar 13, 2008"
49 .SH NAME
50 wait \- await process completion
51 .SH SYNOPSIS
52 .LP
53 .nf
54
55 .fi
56
57 .SS "/bin/sh"
58 .LP
59 .nf
60 \fBwait\fR [\fIpid\fR]...
61 .fi
62
63 .SS "/bin/jsh /bin/ksh /usr/xpg4/bin/sh"
64 .LP
65 .nf
66 \fBwait\fR [\fIpid\fR]...
67 .fi
68
69 .LP
70 .nf
71 \fBwait\fR [% \fIjobid\fR...]
72 .fi
73
74 .SS "/bin/csh"
75 .LP
76 .nf
77 \fBwait\fR
78 .fi
79
80 .SS "ksh93"
81 .LP
82 .nf
83 \fBwait\fR [\fIjob...\fR]
84 .fi
85
86 .SH DESCRIPTION
87 .sp
88 .LP
89 The shell itself executes \fBwait\fR, without creating a new process. If you
90 get the error message \fBcannot fork,too many processes\fR, try using the
91 \fBwait\fR command to clean up your background processes. If this doesn't help,
92 the system process table is probably full or you have too many active
93 foreground processes. There is a limit to the number of process \fBID\fRs
94 associated with your login, and to the number the system can keep track of.
95 .sp
96 .LP
97 Not all the processes of a pipeline with three or more stages are children of
98 the shell, and thus cannot be waited for.
99 .SS "/bin/sh, /bin/jsh"
100 .sp
101 .LP
102 Wait for your background process whose process \fBID\fR is \fIpid\fR and report
103 its termination status. If \fIpid\fR is omitted, all your shell's currently
104 active background processes are waited for and the return code is \fB0\fR. The
105 \fBwait\fR utility accepts a job identifier, when Job Control is enabled (jsh),
106 and the argument, \fIjobid\fR, is preceded by a percent sign (\fB%\fR).
107 .sp
108 .LP
109 If \fIpid\fR is not an active process \fBID,\fR the \fBwait\fR utility returns
110 immediately and the return code is \fB0\fR.
111 .SS "csh"
112 .sp
113 .LP
114 Wait for your background processes.
115 .SS "ksh"
116 .sp
117 .LP
118 When an asynchronous list is started by the shell, the process \fBID\fR of the
119 last command in each element of the asynchronous list becomes known in the
120 current shell execution environment.
121 .sp
122 .LP
123 If the \fBwait\fR utility is invoked with no operands, it waits until all
124 process \fBIDs\fR known to the invoking shell have terminated and exit with an
125 exit status of \fB0\fR.
126 .sp
127 .LP
128 If one or more \fIpid\fR or \fIjobid\fR operands are specified that represent
129 known process \fBID\fRs (or jobids), the \fBwait\fR utility waits until all of
130 them have terminated. If one or more \fIpid\fR or \fIjobid\fR operands are
131 specified that represent unknown process \fBID\fRs (or jobids), \fBwait\fR
132 treats them as if they were known process \fBID\fRs (or jobids) that exited
133 with exit status \fB127\fR. The exit status returned by the \fBwait\fR utility
134 is the exit status of the process requested by the last \fIpid\fR or
135 \fIjobid\fR operand.
136 .sp
137 .LP
138 The known process \fBID\fRs are applicable only for invocations of \fBwait\fR
139 in the current shell execution environment.
140 .SS "ksh93"
141 .sp
142 .LP
143 wait with no operands, waits until all jobs known to the invoking shell have
144 terminated. If one or more job operands are specified, wait waits until all of
145 them have completed. Each job can be specified as one of the following:
146 .sp
147 .ne 2
148 .na
149 \fB\fInumber\fR\fR
150 .ad
151 .RS 12n
152 \fInumber\fR refers to a process ID.
153 .RE
154
155 .sp
156 .ne 2
157 .na
158 \fB\fB-\fR\fInumber\fR\fR
159 .ad
160 .RS 12n
161 \fInumber\fR refers to a process group ID.
162 .RE
195 .ad
196 .br
197 .na
198 \fB\fB%%\fR\fR
199 .ad
200 .RS 12n
201 Refers to the current job
202 .RE
203
204 .sp
205 .ne 2
206 .na
207 \fB\fB%-\fR\fR
208 .ad
209 .RS 12n
210 Refers to the previous job
211 .RE
212
213 .sp
214 .LP
215 If one ore more job operands is a process id or process group id not known by
216 the current shell environment, \fBwait\fR treats each of them as if it were a
217 process that exited with status 127.
218 .SH OPERANDS
219 .sp
220 .LP
221 The following operands are supported:
222 .sp
223 .ne 2
224 .na
225 \fB\fIpid\fR\fR
226 .ad
227 .RS 9n
228 The unsigned decimal integer process \fBID\fR of a command, for which the
229 utility is to wait for the termination.
230 .RE
231
232 .sp
233 .ne 2
234 .na
235 \fB\fIjobid\fR\fR
236 .ad
237 .RS 9n
238 A job control job \fBID\fR that identifies a background process group to be
239 waited for. The job control job \fBID\fR notation is applicable only for
240 invocations of \fBwait\fR in the current shell execution environment, and only
241 on systems supporting the job control option.
242 .RE
243
244 .SH USAGE
245 .sp
246 .LP
247 On most implementations, \fBwait\fR is a shell built-in. If it is called in a
248 subshell or separate utility execution environment, such as one of the
249 following,
250 .sp
251 .in +2
252 .nf
253 (wait)
254 nohup wait ...
255 find . -exec wait ... \e;
256 .fi
257 .in -2
258 .sp
259
260 .sp
261 .LP
262 it returns immediately because there is no known process \fBID\fRs to wait for
263 in those environments.
264 .SH EXAMPLES
265 .LP
266 \fBExample 1 \fRUsing A Script To Identify The Termination Signal
267 .sp
268 .LP
269 Although the exact value used when a process is terminated by a signal is
270 unspecified, if it is known that a signal terminated a process, a script can
271 still reliably figure out which signal is using \fBkill\fR, as shown by the
272 following (\fB/bin/ksh\fR and \fB/usr/xpg4/bin/sh\fR):
273
274 .sp
275 .in +2
276 .nf
277 sleep 1000&
278 pid=$!
279 kill -kill $pid
280 wait $pid
281 echo $pid was terminated by a SIG$(kill -l $(($?\(mi128))) signal.
282 .fi
283 .in -2
284 .sp
285
298 jobs -l %%
299 .fi
300 .in -2
301 .sp
302
303 .sp
304 .LP
305 then either of the following commands returns the exit status of the second
306 \fBsleep\fR in the pipeline:
307
308 .sp
309 .in +2
310 .nf
311 wait <\fIpid of sleep 31\fR>
312 wait %%
313 .fi
314 .in -2
315 .sp
316
317 .SH ENVIRONMENT VARIABLES
318 .sp
319 .LP
320 See \fBenviron\fR(5) for descriptions of the following environment variables
321 that affect the execution of \fBwait\fR: \fBLANG\fR, \fBLC_ALL\fR,
322 \fBLC_CTYPE\fR, \fBLC_MESSAGES\fR, and \fBNLSPATH\fR.
323 .SH EXIT STATUS
324 .SS "ksh93"
325 .sp
326 .LP
327 The following exit values are returned by the \fBwait\fR built-in in
328 \fBksh93\fR:
329 .sp
330 .ne 2
331 .na
332 \fB\fB0\fR\fR
333 .ad
334 .RS 7n
335 \fBwait\fR was invoked with no operands. All processes known by the invoking
336 process have terminated.
337 .RE
338
339 .sp
340 .ne 2
341 .na
342 \fB\fB127\fR\fR
343 .ad
344 .RS 7n
345 \fIjob\fR is a process id or process group id that is unknown to the current
346 shell environment.
347 .RE
348
349 .SH ATTRIBUTES
350 .sp
351 .LP
352 See \fBattributes\fR(5) for descriptions of the following attributes:
353 .sp
354
355 .sp
356 .TS
357 box;
358 c | c
359 l | l .
360 ATTRIBUTE TYPE ATTRIBUTE VALUE
361 _
362 Interface Stability Committed
363 _
364 Standard See \fBstandards\fR(5).
365 .TE
366
367 .SH SEE ALSO
368 .sp
369 .LP
370 \fBcsh\fR(1), \fBjobs\fR(1), \fBksh\fR(1), \fBksh93\fR(1), \fBsh\fR(1),
371 \fBattributes\fR(5), \fBenviron\fR(5), \fBstandards\fR(5)
|
28 .\" Common Development and Distribution License (the "License").
29 .\" You may not use this file except in compliance with the License.
30 .\"
31 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
32 .\" or http://www.opensolaris.org/os/licensing.
33 .\" See the License for the specific language governing permissions
34 .\" and limitations under the License.
35 .\"
36 .\" When distributing Covered Code, include this CDDL HEADER in each
37 .\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
38 .\" If applicable, add the following below this CDDL HEADER, with the
39 .\" fields enclosed by brackets "[]" replaced with your own identifying
40 .\" information: Portions Copyright [yyyy] [name of copyright owner]
41 .\"
42 .\"
43 .\" Copyright 1989 AT&T
44 .\" Copyright 1992 X/Open Company Limited
45 .\" Portions Copyright (c) 1982-2007 AT&T Knowledge Ventures
46 .\" Copyright (c) 2008, Sun Microsystems, Inc. All Rights Reserved
47 .\"
48 .TH WAIT 1 "May 17, 2020"
49 .SH NAME
50 wait \- await process completion
51 .SH SYNOPSIS
52 .nf
53
54 .fi
55
56 .SS "/bin/sh"
57 .nf
58 \fBwait\fR [\fIpid\fR]...
59 .fi
60
61 .SS "/bin/jsh /bin/ksh /usr/xpg4/bin/sh"
62 .nf
63 \fBwait\fR [\fIpid\fR]...
64 .fi
65
66 .LP
67 .nf
68 \fBwait\fR [% \fIjobid\fR...]
69 .fi
70
71 .SS "/bin/csh"
72 .nf
73 \fBwait\fR
74 .fi
75
76 .SS "ksh93"
77 .nf
78 \fBwait\fR [\fIjob...\fR]
79 .fi
80
81 .SH DESCRIPTION
82 The shell itself executes \fBwait\fR, without creating a new process. If you
83 get the error message \fBcannot fork,too many processes\fR, try using the
84 \fBwait\fR command to clean up your background processes. If this doesn't help,
85 the system process table is probably full or you have too many active
86 foreground processes. There is a limit to the number of process \fBID\fRs
87 associated with your login, and to the number the system can keep track of.
88 .sp
89 .LP
90 Not all the processes of a pipeline with three or more stages are children of
91 the shell, and thus cannot be waited for.
92 .SS "/bin/sh, /bin/jsh"
93 Wait for your background process whose process \fBID\fR is \fIpid\fR and report
94 its termination status. If \fIpid\fR is omitted, all your shell's currently
95 active background processes are waited for and the return code is \fB0\fR. The
96 \fBwait\fR utility accepts a job identifier, when Job Control is enabled (jsh),
97 and the argument, \fIjobid\fR, is preceded by a percent sign (\fB%\fR).
98 .sp
99 .LP
100 If \fIpid\fR is not an active process \fBID,\fR the \fBwait\fR utility returns
101 immediately and the return code is \fB0\fR.
102 .SS "csh"
103 Wait for your background processes.
104 .SS "ksh"
105 When an asynchronous list is started by the shell, the process \fBID\fR of the
106 last command in each element of the asynchronous list becomes known in the
107 current shell execution environment.
108 .sp
109 .LP
110 If the \fBwait\fR utility is invoked with no operands, it waits until all
111 process \fBIDs\fR known to the invoking shell have terminated and exit with an
112 exit status of \fB0\fR.
113 .sp
114 .LP
115 If one or more \fIpid\fR or \fIjobid\fR operands are specified that represent
116 known process \fBID\fRs (or jobids), the \fBwait\fR utility waits until all of
117 them have terminated. If one or more \fIpid\fR or \fIjobid\fR operands are
118 specified that represent unknown process \fBID\fRs (or jobids), \fBwait\fR
119 treats them as if they were known process \fBID\fRs (or jobids) that exited
120 with exit status \fB127\fR. The exit status returned by the \fBwait\fR utility
121 is the exit status of the process requested by the last \fIpid\fR or
122 \fIjobid\fR operand.
123 .sp
124 .LP
125 The known process \fBID\fRs are applicable only for invocations of \fBwait\fR
126 in the current shell execution environment.
127 .SS "ksh93"
128 wait with no operands, waits until all jobs known to the invoking shell have
129 terminated. If one or more job operands are specified, wait waits until all of
130 them have completed. Each job can be specified as one of the following:
131 .sp
132 .ne 2
133 .na
134 \fB\fInumber\fR\fR
135 .ad
136 .RS 12n
137 \fInumber\fR refers to a process ID.
138 .RE
139
140 .sp
141 .ne 2
142 .na
143 \fB\fB-\fR\fInumber\fR\fR
144 .ad
145 .RS 12n
146 \fInumber\fR refers to a process group ID.
147 .RE
180 .ad
181 .br
182 .na
183 \fB\fB%%\fR\fR
184 .ad
185 .RS 12n
186 Refers to the current job
187 .RE
188
189 .sp
190 .ne 2
191 .na
192 \fB\fB%-\fR\fR
193 .ad
194 .RS 12n
195 Refers to the previous job
196 .RE
197
198 .sp
199 .LP
200 If one or more job operands is a process id or process group id not known by
201 the current shell environment, \fBwait\fR treats each of them as if it were a
202 process that exited with status 127.
203 .SH OPERANDS
204 The following operands are supported:
205 .sp
206 .ne 2
207 .na
208 \fB\fIpid\fR\fR
209 .ad
210 .RS 9n
211 The unsigned decimal integer process \fBID\fR of a command, for which the
212 utility is to wait for the termination.
213 .RE
214
215 .sp
216 .ne 2
217 .na
218 \fB\fIjobid\fR\fR
219 .ad
220 .RS 9n
221 A job control job \fBID\fR that identifies a background process group to be
222 waited for. The job control job \fBID\fR notation is applicable only for
223 invocations of \fBwait\fR in the current shell execution environment, and only
224 on systems supporting the job control option.
225 .RE
226
227 .SH USAGE
228 On most implementations, \fBwait\fR is a shell built-in. If it is called in a
229 subshell or separate utility execution environment, such as one of the
230 following,
231 .sp
232 .in +2
233 .nf
234 (wait)
235 nohup wait ...
236 find . -exec wait ... \e;
237 .fi
238 .in -2
239 .sp
240
241 .sp
242 .LP
243 it returns immediately because there is no known process \fBID\fRs to wait for
244 in those environments.
245 .SH EXAMPLES
246 \fBExample 1 \fRUsing A Script To Identify The Termination Signal
247 .sp
248 .LP
249 Although the exact value used when a process is terminated by a signal is
250 unspecified, if it is known that a signal terminated a process, a script can
251 still reliably figure out which signal is using \fBkill\fR, as shown by the
252 following (\fB/bin/ksh\fR and \fB/usr/xpg4/bin/sh\fR):
253
254 .sp
255 .in +2
256 .nf
257 sleep 1000&
258 pid=$!
259 kill -kill $pid
260 wait $pid
261 echo $pid was terminated by a SIG$(kill -l $(($?\(mi128))) signal.
262 .fi
263 .in -2
264 .sp
265
278 jobs -l %%
279 .fi
280 .in -2
281 .sp
282
283 .sp
284 .LP
285 then either of the following commands returns the exit status of the second
286 \fBsleep\fR in the pipeline:
287
288 .sp
289 .in +2
290 .nf
291 wait <\fIpid of sleep 31\fR>
292 wait %%
293 .fi
294 .in -2
295 .sp
296
297 .SH ENVIRONMENT VARIABLES
298 See \fBenviron\fR(5) for descriptions of the following environment variables
299 that affect the execution of \fBwait\fR: \fBLANG\fR, \fBLC_ALL\fR,
300 \fBLC_CTYPE\fR, \fBLC_MESSAGES\fR, and \fBNLSPATH\fR.
301 .SH EXIT STATUS
302 .SS "ksh93"
303 The following exit values are returned by the \fBwait\fR built-in in
304 \fBksh93\fR:
305 .sp
306 .ne 2
307 .na
308 \fB\fB0\fR\fR
309 .ad
310 .RS 7n
311 \fBwait\fR was invoked with no operands. All processes known by the invoking
312 process have terminated.
313 .RE
314
315 .sp
316 .ne 2
317 .na
318 \fB\fB127\fR\fR
319 .ad
320 .RS 7n
321 \fIjob\fR is a process id or process group id that is unknown to the current
322 shell environment.
323 .RE
324
325 .SH ATTRIBUTES
326 See \fBattributes\fR(5) for descriptions of the following attributes:
327 .sp
328
329 .sp
330 .TS
331 box;
332 c | c
333 l | l .
334 ATTRIBUTE TYPE ATTRIBUTE VALUE
335 _
336 Interface Stability Committed
337 _
338 Standard See \fBstandards\fR(5).
339 .TE
340
341 .SH SEE ALSO
342 \fBcsh\fR(1), \fBjobs\fR(1), \fBksh\fR(1), \fBksh93\fR(1), \fBsh\fR(1),
343 \fBattributes\fR(5), \fBenviron\fR(5), \fBstandards\fR(5)
|