How to time several background processes

time

I have a script s:

echo a &
echo b &
echo c &

Now I want to know how much time it will take for the script to finish.
I try

time bash s

But it gives me an immediate result which is not the correct one(my script is of course much more complicated than that I've written here and takes a lot of time)
How can I ask time to wait for all the subprocesses to finish.

Best Answer

Add wait to the very end of the script. This will make the script wait for all background processes to exit before continuing.

The new script:

echo a &
echo b &
echo c &

wait
Related Question