Wait
Encyclopedia
In computing
Computing
Computing is usually defined as the activity of using and improving computer hardware and software. It is the computer-specific part of information technology...

, wait is a command
Command (computing)
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....

 which pauses until execution of a background process
Background (computer software)
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....

 has ended.

Usage


wait [n]


where n is the pid
Process identifier
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.

wait normally returns the exit status
Exit status
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.

  1. !/bin/bash

  1. Parallel update script which makes use of the wait command

  1. Update local copy

rsync iona:src/ . &
  1. Upgrade required libraries, or exit indicating failure if make failed for some reason

make -C lib || exit 1
  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

External links

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK