Created
October 23, 2014 09:33
-
-
Save hktonylee/7d8f7eb7c8586cb2c489 to your computer and use it in GitHub Desktop.
Fork Processes in Shell (With Smart Cleanup)
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
ALL_PIDS=() | |
on_die() { | |
for pid in "${ALL_PIDS[@]}"; do | |
echo "Killing $pid..." | |
kill -9 $pid | |
done | |
} | |
add() { | |
# change this | |
python client.py "$@" & | |
ALL_PIDS+=($!) | |
} | |
trap on_die TERM | |
trap on_die SIGINT | |
# add here | |
add 11 | |
add 11 | |
add 22 | |
add 33 | |
wait | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment