Skip to content

Instantly share code, notes, and snippets.

@aholmes
Created January 14, 2014 03:18
Show Gist options
  • Save aholmes/8412456 to your computer and use it in GitHub Desktop.
Save aholmes/8412456 to your computer and use it in GitHub Desktop.
#!/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