Wednesday, April 20, 2011

Wait, wait!!

After years of shell scripting I wasn't aware of the useful "wait" command. It makes the parent process wait until all child processes finish. I mean:


(sleep 5; echo "good bye from child 1") &
(sleep 10; echo "good bye from child 2") &

echo "good bye from parent process"

When executed, this script will output:

good bye from child 1
good bye from child 2
good bye from parent process

Arggg, so many lost hours writing custom code to do what was only one line away.