Created
April 7, 2014 17:55
-
-
Save BenWhitehead/10025413 to your computer and use it in GitHub Desktop.
Fork some process and wait for all forks to complete
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
PIDS="" | |
function fork() { | |
echo "sleeping ${1}s" && sleep ${1}s && echo "slept ${1}s" & | |
PIDS="${PIDS} $!" | |
} | |
fork 2 | |
fork 4 | |
fork 8 | |
fork 16 | |
for pid in ${PIDS}; do | |
wait ${pid} | |
done | |
echo "Complete" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment