Skip to content

Instantly share code, notes, and snippets.

@samthor
Created April 13, 2015 00:04
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 samthor/73e9d8a66642cb6915f6 to your computer and use it in GitHub Desktop.
Save samthor/73e9d8a66642cb6915f6 to your computer and use it in GitHub Desktop.
library to run subprocesses in bash
#!/bin/bash
# Library which causes a bash script to block until killed, shutting down its
# child processes when complete.
function _death {
echo "killing all subprocesses" 1>&2
pkill -P $$
exit 0 # still need to quit
}
trap _death SIGINT SIGTERM
function _runner {
set -eu
while true; do sleep 3600; done
}
trap _runner EXIT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment