Skip to content

Instantly share code, notes, and snippets.

@BenWhitehead
Created April 7, 2014 17:55
Show Gist options
  • Save BenWhitehead/10025413 to your computer and use it in GitHub Desktop.
Save BenWhitehead/10025413 to your computer and use it in GitHub Desktop.
Fork some process and wait for all forks to complete
#!/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