Last active
August 29, 2015 14:16
-
-
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
This file contains hidden or 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
#!/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