Wait (command)
| wait | |
|---|---|
| Developer | AT&T Bell Laboratories |
| Release | November 1973 |
| 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.
Usage
wait [n...]
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 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 specifications it is required to be a shell builtin. [1]
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
References
- ^ "The Open Group Base Specifications Issue 8". The Open Group. 2024. Archived from the original on May 18, 2025. Retrieved May 14, 2025.
External links
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.