2019-03-31 17:05:09 +08:00
.. _cmd-wait:
2018-12-17 09:39:33 +08:00
wait - wait for jobs to complete
2019-01-03 12:10:47 +08:00
================================
2018-12-17 09:39:33 +08:00
2018-12-18 09:58:24 +08:00
Synopsis
--------
2018-12-17 05:08:41 +08:00
2019-09-17 17:59:04 +08:00
::
2018-12-18 09:58:24 +08:00
2019-09-17 17:59:04 +08:00
wait [-n | --any] [PID | PROCESS_NAME] ...
2018-12-17 05:08:41 +08:00
2018-12-19 10:44:30 +08:00
Description
2019-01-03 12:10:47 +08:00
-----------
2018-12-17 05:08:41 +08:00
2018-12-20 04:02:45 +08:00
`` wait `` waits for child jobs to complete.
2018-12-17 05:08:41 +08:00
- If a pid is specified, the command waits for the job that the process with the pid belongs to.
- If a process name is specified, the command waits for the jobs that the matched processes belong to.
- If neither a pid nor a process name is specified, the command waits for all background jobs.
2018-12-20 04:02:45 +08:00
- If the `` -n `` / `` --any `` flag is provided, the command returns as soon as the first job completes. If it is not provided, it returns after all jobs complete.
2018-12-17 05:08:41 +08:00
2018-12-19 10:44:30 +08:00
Example
2019-01-03 12:10:47 +08:00
-------
2018-12-17 05:08:41 +08:00
2018-12-19 11:14:04 +08:00
::
sleep 10 &
wait $last_pid
2018-12-20 04:02:45 +08:00
spawns `` sleep `` in the background, and then waits until it finishes.
2018-12-19 11:14:04 +08:00
::
for i in (seq 1 5); sleep 10 &; end
wait
2018-12-17 05:08:41 +08:00
spawns five jobs in the background, and then waits until all of them finishes.
2018-12-19 11:14:04 +08:00
::
for i in (seq 1 5); sleep 10 &; end
hoge &
wait sleep
2019-11-02 02:11:51 +08:00
spawns five jobs and `` hoge `` in the background, and then waits until all `` sleep ` ` \s finish, and doesn't wait for ` ` hoge `` finishing.