Computing is usually defined as the activity of using and improving computer hardware and software. It is the computer-specific part of information technology...
In computing, a command is a directive to a computer program acting as an interpreter of some kind, in order to perform a specific task. Most commonly a command is a directive to some kind of command line interface, such as a shell....
A background process is a computer process that runs "behind the scenes" and without user intervention. Typical tasks for these processes include logging, system monitoring, scheduling, and user notification....
In computing, the process identifier is a number used by most operating system kernels to uniquely identify a process...
or job ID of a currently executing background process (job). If n is not given, the command waits until all jobs known to the invoking shell have terminated.
The exit status or return code of a process in computer programming is a small number passed from a child process to a parent process when it has finished executing a specific procedure or delegated task...
of the last job which terminated. It may also return 127 in the event that n specifies a non-existent job or zero if there were no jobs to wait for.
Because wait needs to be aware of the job table of the current shell execution environment, it is usually implemented as a shell builtin
Shell builtin
In computing, a shell builtin is a command or a function, called from a shell, that is executed directly in the shell itself, instead of an external executable program which the shell would load and execute....
.
Example
This command can be useful where part of a script can execute in parallel to implement a barrier where an upcoming section depends on the successful completion of the preceding sections.
The following example will fetch the src/ directory from a machine named iona using rsync
Rsync
rsync is a software application and network protocol for Unix-like and Windows systems which synchronizes files and directories from one location to another while minimizing data transfer using delta encoding when appropriate. An important feature of rsync not found in most similar...
and simultaneously update the libraries on which this program depends, before building the combination.
!/bin/bash
Parallel update script which makes use of the wait command
Update local copy
rsync iona:src/ . &
Upgrade required libraries, or exit indicating failure if make failed for some reason
make -C lib || exit 1
Wait for rsync to terminate (may have already happened) and finish the job, unless rsync failed
wait && make
Wait for specified job control id number:
$ ls -R / > /dev/null 2>&1 & # start any long running background process
[2] 1986
$ wait %2 # waits for background job number 2 to terminate, then returns