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.
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
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.
ISO/IEC DIS 99452:1992, Information technology Portable Operating System Interface (POSIX) Part 2: Shell and Utilities (IEEE Std 1003.21992);
AT&T SVID Issue 2;
X/Open CAE Specification, Commands and Utilities, Issue 4, 1992.