Skip to content

Instantly share code, notes, and snippets.

@hktonylee
Created October 23, 2014 09:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hktonylee/7d8f7eb7c8586cb2c489 to your computer and use it in GitHub Desktop.
Save hktonylee/7d8f7eb7c8586cb2c489 to your computer and use it in GitHub Desktop.
Fork Processes in Shell (With Smart Cleanup)
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