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