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