2019-03-31 09:05:09 +00:00
.. _cmd-wait:
2018-12-17 01:39:33 +00:00
wait - wait for jobs to complete
2019-01-03 04:10:47 +00:00
================================
2018-12-17 01:39:33 +00:00
2018-12-18 01:58:24 +00:00
Synopsis
--------
2018-12-16 21:08:41 +00:00
wait [-n | --any] [PID | PROCESS_NAME] ...
2018-12-18 01:58:24 +00:00
2018-12-16 21:08:41 +00:00
2018-12-19 02:44:30 +00:00
Description
2019-01-03 04:10:47 +00:00
-----------
2018-12-16 21:08:41 +00:00
2018-12-19 20:02:45 +00:00
`` wait `` waits for child jobs to complete.
2018-12-16 21:08:41 +00: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-19 20:02:45 +00: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-16 21:08:41 +00:00
2018-12-19 02:44:30 +00:00
Example
2019-01-03 04:10:47 +00:00
-------
2018-12-16 21:08:41 +00:00
2018-12-19 03:14:04 +00:00
::
sleep 10 &
wait $last_pid
2018-12-19 20:02:45 +00:00
spawns `` sleep `` in the background, and then waits until it finishes.
2018-12-19 03:14:04 +00:00
::
for i in (seq 1 5); sleep 10 &; end
wait
2018-12-16 21:08:41 +00:00
spawns five jobs in the background, and then waits until all of them finishes.
2018-12-19 03:14:04 +00:00
::
for i in (seq 1 5); sleep 10 &; end
hoge &
wait sleep
2018-12-19 20:02:45 +00:00
spawns five jobs and `` hoge `` in the background, and then waits until all `` sleep ` ` s finishes, and doesn't wait for ` ` hoge `` finishing.