Created
June 24, 2014 18:36
-
-
Save kumichou/7312f01fc3128325986a to your computer and use it in GitHub Desktop.
Ever wanted to see how to do something simple like catch Ctrl-C in a BASH script? I'll illustrate how to start two different Python "apps" that would normally take over the terminal and stop them both
This file contains 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
#!/usr/bin/env bash | |
CWD=`pwd` | |
function cleanup { | |
echo "You pressed Ctrl-C, time to exit the Python Services"; | |
ps aux | grep myservice2 | grep -v grep | awk '{print $2}' | xargs kill -9; | |
ps aux | grep myservice1 | grep -v grep | awk '{print $2}' | xargs kill -9; | |
exit 1; | |
} | |
trap cleanup INT | |
cd ${CWD}/myservice1/myservice1-main.py & | |
cd ${CWD}/myservice2/myservice2-main.py | |
wait |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment