How to wait on all child (and grandchild etc) process spawned by a script

You can use wait to wait for all the background processes started by userscript to complete. Since wait only works on children of the current shell, you’ll need to source their script instead of running it as a separate process.

( source userscript; wait )

Sourcing the script in an explicit subshell should simulate starting a new process closely enough. If not, you can also background the subshell, which forces a new process to be started, then wait for it to complete.

( source userscript; wait ) & wait

Leave a Comment