Wait (command)

Short description: Command which pauses until execution of a background process has ended

waitDeveloper(s)| AT&T Bell Laboratories

|

Initial release| November 1973; 52 years ago (1973-11)
Operating system| Unix and Unix-like
Type| Command

In Unix shells, `wait` is a command which pauses until execution of a background process has ended.

## Contents

* 1 Usage
* 2 Example
* 3 See also
* 4 External links

## Usage

wait [n]

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

## 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 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
[2] 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

* v
* t
* e

Unix command-line interface programs and shell builtins

File system|

* cat
* chmod
* chown
* chgrp
* cksum
* cmp
* cp
* dd
* du
* df
* file
* fuser
* ln
* ls
* mkdir
* mv
* pax
* pwd
* rm
* rmdir
* split
* tee
* touch
* type
* umask

Processes|

* at
* bg
* crontab
* fg
* kill
* nice
* ps
* time

User environment|

* env
* exit
* logname
* mesg
* talk
* tput
* uname
* who
* write

Text processing|

* awk
* basename
* comm
* csplit
* cut
* diff
* dirname
* ed
* ex
* fold
* head
* iconv
* join
* m4
* more
* nl
* paste
* patch
* printf
* sed
* sort
* strings
* tail
* tr
* uniq
* vi
* wc
* xargs

Shell builtins|

* alias
* cd
* echo
* test
* unset
* wait

Searching|

* find
* grep

Documentation|

* man

Software development|

* ar
* ctags
* lex
* make
* nm
* strip
* yacc

Miscellaneous|

* bc
* cal
* expr
* lp
* od
* sleep
* true and false

* Categories
* Standard Unix programs
* Unix SUS2008 utilities
* List

0.00

(0 votes)

Original source: https://en.wikipedia.org/wiki/Wait (command). Read more

|

Retrieved from "https://handwiki.org/wiki/index.php?title=Software:Wait_(command)&oldid=776872"
*[v]: View this template
*[t]: Discuss this template
*[e]: Edit this template