I have a script that collects some information from several different
sources, commands that should run in parallel. As soon as all
this data has been collected I want to process it but it's important
that I don't start this until all commands has finished.
With the wait command in bash you can force the execution of
the script to pause until a specific or all background jobs has
finished executing before continuing the execution of your script.
So by putting my collection jobs in the background and putting in a
wait I manged to speed up the total execution time by quite a lot.
#!/bin/bash collect-job1.sh & collect-job2.sh & collect-job3.sh & wait process-job-output.sh wait # to not exit the containing script until all execution has finished