HOME

TheInfoList



OR:

In
Unix Unix (, ; trademarked as UNIX) is a family of multitasking, multi-user 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, a ...
shells, wait is a
command Command may refer to: Computing * Command (computing), a statement in a computer language * command (Unix), a Unix command * COMMAND.COM, the default operating system shell and command-line interpreter for DOS * Command key, a modifier key on A ...
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. On a Wind ...
has ended.


Usage

wait ... where n... is a list of pids or job IDs of a currently executing background process (job). If no ids are provided, the command waits until all jobs known to the invoking shell have terminated. wait normally returns the
exit status In computing, the exit status (also exit code or exit value) of a terminated process is an integer number that is made available to its parent process (or caller). In DOS, this may be referred to as an errorlevel. When computer programs ar ...
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. Under the
POSIX The Portable Operating System Interface (POSIX; ) is a family of standards specified by the IEEE Computer Society for maintaining compatibility between operating systems. POSIX defines application programming interfaces (APIs), along with comm ...
specifications it is required to be a
shell builtin In computing, a shell builtin is a Command (computing), command or a Subroutine, function, exposed by a Shell (computing), shell, that is implemented in the shell itself, instead of an external computer program, program which the shell would load a ...
.


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 (remote sync) is a utility for 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)


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