Wait for your background processes whose process IDs are the values of pid and report termination status. Any pid which represents an unknown process ID is treated as if it were a known process ID that exited with exit status 127.
If pid is omitted, all your shell's currently active background processes are waited for.
The shell itself executes wait, without creating a new process.
If wait is invoked with one or more pid arguments, and the processes of all the given pids have terminated or are not known to the invoking shell, and the status of the last pid is known, then the exit status is that of the last pid.
If wait terminated abnormally due to the receipt of a signal, the exit status is greater than 128.
Otherwise, wait exits with one of the following values:
cannot fork, too many processes, try using the wait 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 ids associated with your login, and to the number the system can keep track of.)
Not all the processes of a 3- or more-stage pipeline are children of the shell, and thus cannot be waited for.
If pid is not an active process id, wait returns immediately.