DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 

wait(C)


wait -- await completion of background processes

Syntax

wait [ pid ... ]

Description

With no arguments, the wait command waits until all background processes known to the current shell have terminated; wait then exits with a value of 0 (zero). (Background processes are started with an ampersand &.)

If a list of process IDs is supplied, wait attends only those processes, and exits when the last process exits. wait returns the exit value of the process specified by the final pid on the command line. If the process pid was unknown to the shell, the exit value is 127. If the process was killed by any signal, wait returns an exit value greater than 128.

Because the wait(S-osr5) system call must be executed in the parent process, the shell itself executes wait, without creating a new process. wait is built into csh(C), ksh(C), and sh(C).

The version of kill built into ksh accepts job IDs as well as process IDs if job control is enabled. See ksh(C) for details. Refer to jobs(C) for details of acceptable job ID formats.

Exit values

Examples

You can find out what signal killed a child process using the -l option to kill(C):
   program &		# start the background process
   pid=$!			# get process ID
   wait $pid		# wait for the process to terminate
   if [ $? -gt 128 ]	# check the exit value
   then
   	echo $pid killed by signal SIG$(kill -l $?)
   fi

Limitations

wait can only report abnormal terminations using its exit value.

The shell can track the status of at most {CHILD_MAX} processes.

The shell discards the previous value of the ! shell parameter when a new background process is started.

See also

bg(C), csh(C), fg(C), jobs(C), kill(C), ksh(C), sh(C)

Standards conformance

wait is conformant with:

ISO/IEC DIS 9945-2:1992, Information technology - Portable Operating System Interface (POSIX) - Part 2: Shell and Utilities (IEEE Std 1003.2-1992);
AT&T SVID Issue 2;
X/Open CAE Specification, Commands and Utilities, Issue 4, 1992.


© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 -- 03 June 2005