Skip to content

Instantly share code, notes, and snippets.

@ryanmark
Last active August 29, 2015 14:16
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 ryanmark/daf872c46076401f69c4 to your computer and use it in GitHub Desktop.
Save ryanmark/daf872c46076401f69c4 to your computer and use it in GitHub Desktop.
This tiny script allows you to run many things in the background, then shuts them all down when you hit ctrl-c
#!/bin/bash
# This tiny script allows you to run many things in the background, then shuts them all down
# when you hit ctrl-c. Put your commands below, and be sure to include the & at the end of the
# line to make the command run in the background.
# Your commands here
# EX: compass watch &
# Kill all subprocesses when the user does ctrl-c
trap "killtree $$" SIGINT
killtree() {
local parent=$1 child
for child in $(ps -o ppid= -o pid= | awk "\$1==$parent {print \$2}"); do
killtree $child
done
kill $parent > /dev/null 2>&1
}
wait
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment