Skip to content

Instantly share code, notes, and snippets.

@jjt
Created June 1, 2012 17:55
Show Gist options
  • Save jjt/2854018 to your computer and use it in GitHub Desktop.
Save jjt/2854018 to your computer and use it in GitHub Desktop.
Example: Running multiple background processes in one bash script, killing all on SIGINT (ctrl+c)
#!/bin/bash
SITE=/home/dev/sites/rmx
# Arbitrary shell commands, some run in background
echo "RMX using siteroot=$SITE"
$SITE/rmx/manage.py runserver &
compass watch $SITE/media/compass/ &
coffee -o $SITE/media/js -cw $SITE/media/coffee &
hamlpy-watcher $SITE/templates/hamlpy $SITE/templates/templates &
# The magic line
# $$ holds the PID for this script
# Negation means kill by process group id instead of PID
trap "kill -TERM -$$" SIGINT
wait
@vlttnv
Copy link

vlttnv commented Mar 28, 2014

Thanks!

@BorisWouters
Copy link

Nice, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment