2 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for
3 .\" permission to reproduce portions of its copyrighted documentation.
4 .\" Original documentation from The Open Group can be obtained online at
5 .\" http://www.opengroup.org/bookstore/.
7 .\" The Institute of Electrical and Electronics Engineers and The Open
8 .\" Group, have given us permission to reprint portions of their
11 .\" In the following statement, the phrase ``this text'' refers to portions
12 .\" of the system documentation.
14 .\" Portions of this text are reprinted and reproduced in electronic form
15 .\" in the SunOS Reference Manual, from IEEE Std 1003.1, 2004 Edition,
16 .\" Standard for Information Technology -- Portable Operating System
17 .\" Interface (POSIX), The Open Group Base Specifications Issue 6,
18 .\" Copyright (C) 2001-2004 by the Institute of Electrical and Electronics
19 .\" Engineers, Inc and The Open Group. In the event of any discrepancy
20 .\" between these versions and the original IEEE and The Open Group
21 .\" Standard, the original IEEE and The Open Group Standard is the referee
22 .\" document. The original Standard can be obtained online at
23 .\" http://www.opengroup.org/unix/online.html.
25 .\" This notice shall appear on any product containing this material.
27 .\" The contents of this file are subject to the terms of the
28 .\" Common Development and Distribution License (the "License").
29 .\" You may not use this file except in compliance with the License.
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.
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]
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
48 .TH WAIT 1 "Mar 13, 2008"
50 wait \- await process completion
60 \fBwait\fR [\fIpid\fR]...
63 .SS "/bin/jsh /bin/ksh /usr/bin/sh"
66 \fBwait\fR [\fIpid\fR]...
71 \fBwait\fR [% \fIjobid\fR...]
83 \fBwait\fR [\fIjob...\fR]
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.
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"
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).
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.
114 Wait for your background processes.
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.
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.
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
138 The known process \fBID\fRs are applicable only for invocations of \fBwait\fR
139 in the current shell execution environment.
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:
152 \fInumber\fR refers to a process ID.
158 \fB\fB-\fR\fInumber\fR\fR
161 \fInumber\fR refers to a process group ID.
167 \fB\fB%\fR\fInumber\fR\fR
170 \fInumber\fR refers to a job number
176 \fB\fB%\fR\fIstring\fR\fR
179 Refers to a job whose name begins with \fIstring\fR
185 \fB\fB%?\fR\fIstring\fR\fR
188 Refers to a job whose name contains \fIstring\fR
201 Refers to the current job
210 Refers to the previous job
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.
221 The following operands are supported:
228 The unsigned decimal integer process \fBID\fR of a command, for which the
229 utility is to wait for the termination.
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.
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
255 find . -exec wait ... \e;
262 it returns immediately because there is no known process \fBID\fRs to wait for
263 in those environments.
266 \fBExample 1 \fRUsing A Script To Identify The Termination Signal
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/bin/sh\fR):
281 echo $pid was terminated by a SIG$(kill -l $(($?\(mi128))) signal.
287 \fBExample 2 \fRReturning The Exit Status Of A Process
290 If the following sequence of commands is run in less than 31 seconds
291 (\fB/bin/ksh\fR and \fB/usr/bin/sh\fR):
296 sleep 257 | sleep 31 &
305 then either of the following commands returns the exit status of the second
306 \fBsleep\fR in the pipeline:
311 wait <\fIpid of sleep 31\fR>
317 .SH ENVIRONMENT VARIABLES
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.
327 The following exit values are returned by the \fBwait\fR built-in in
335 \fBwait\fR was invoked with no operands. All processes known by the invoking
336 process have terminated.
345 \fIjob\fR is a process id or process group id that is unknown to the current
352 See \fBattributes\fR(5) for descriptions of the following attributes:
360 ATTRIBUTE TYPE ATTRIBUTE VALUE
362 Interface Stability Committed
364 Standard See \fBstandards\fR(5).
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)