Created
January 14, 2014 03:18
-
-
Save aholmes/8412456 to your computer and use it in GitHub Desktop.
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 | |
FAILURE=0 | |
do_tasks() { | |
if [[ $FAILURE -eq 0 ]]; then | |
echo -e "Running tasks\n" | |
some_command & | |
some_command & | |
some_command & | |
else | |
echo -e "A task failed. Halting future calls.\n" | |
fi | |
} | |
waitall() { | |
while true; do | |
pids=`jobs -p` | |
if [[ "$pids" == "" ]]; then break; fi | |
for pid in $pids; do | |
if kill -0 $pid 2> /dev/null; then | |
continue; | |
elif wait $pid; then | |
continue; | |
else | |
FAILURE=1 | |
fi | |
done | |
done | |
} | |
do_tasks; | |
waitall; | |
do_tasks; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment