wait command (waits for child processes to complete)
- Organization of this page
Format
wait [pid ...]
Description
This command waits for child processes to complete. Specify for pid one or more process IDs of child processes waiting for completion. If pid is not specified, the command waits for all child processes being executed to complete. If an invalid process ID that begins with a non-numeric value is specified for pid, processing terminates normally with return code 127.
Note the following if a mixture of numeric values and non-numeric values is specified beginning with a numeric value, as shown in the example below: The character string up to the last position preceding the non-numeric value is interpreted as a process ID and the command waits for the child process to complete.
UAP & # Shell variable ! stores the process that started the UAP. wait $!ABC # The wait command interprets the character string preceding ABC and waits for the child process to complete.
When the pid argument is specified, the wait command terminates with the return code of the last process that waited for completion. An example follows:
UAP1 & # UAP1 terminates with a return code of 2. PID1=$! # UAP2 & # UAP2 terminates with a return code of 16. PID2=$! # UAP3 & # UAP3 terminates with a return code of 0. PID3=$! # wait $PID1 $PID2 $PID3 # The wait command terminates with a return code of 0.
Return codes
Return code |
Meaning |
---|---|
0 |
Normal termination |
127 |
Normal termination
|
Other than the above |
Error termination |
Notes
-
Even if the command syntax of this regular built-in command is invalid, it does not exit the shell that is executing the command.
Usage example
-
Wait for the child process with process ID 4848 to complete.
wait 4848