Wait (command)
   HOME

TheInfoList



OR:

In
Unix Unix (; trademarked as UNIX) is a family of multitasking, multiuser computer operating systems that derive from the original AT&T Unix, whose development started in 1969 at the Bell Labs research center by Ken Thompson, Dennis Ritchie, an ...
shells, wait is a
command Command may refer to: Computing * Command (computing), a statement in a computer language * COMMAND.COM, the default operating system shell and command-line interpreter for DOS * Command key, a modifier key on Apple Macintosh computer keyboards * ...
which pauses until execution of a
background process A background process is a computer process that runs ''behind the scenes'' (i.e., in the background) and without user intervention. Typical tasks for these processes include logging, system monitoring, scheduling, and user notification. The backgr ...
has ended.


Usage

wait where n is the pid or
job ID In Unix and Unix-like operating systems, job control refers to control of jobs by a shell, especially interactively, where a "job" is a shell's representation for a process group. Basic job control features are the suspending, resuming, or termina ...
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 The exit status of a process in computer programming is a small number passed from a child process (or callee) to a parent process (or caller) when it has finished executing a specific procedure or delegated task. In DOS, this may be referred ...
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 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. Shell builtins work significantly fa ...
.


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 is a utility for efficiently transferring and synchronizing files between a computer and a storage drive and across networked computers by comparing the modification times and sizes of files. It is commonly found on Unix-like opera ...
and simultaneously update the libraries on which this program depends, before building the combination. #!/usr/bin/env 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 wait make Wait for specified job control id number: $ ls -R / > /dev/null 2>&1 & # start any long running background process 1986 $ wait %2 # waits for background job number 2 to terminate, then returns


See also

*
wait (system call) In computer operating systems, a process (or task) may wait on another process to complete its execution. In most systems, a parent process can create an independently executing child process. The parent process may then issue a ''wait'' system ...


External links


GNU bash reference manual for the wait command
{{Unix commands Unix SUS2008 utilities Unix process- and task-management-related software IBM i Qshell commands