I've got a couple python scripts which I start collectively from a shell script as follows:
#!/bin/bash
python prog1.py &
python prog2.py &
python prog3.py
Since I am developing I often want to stop these processes. I normally do so by hitting ctrl+C, but unfortuntaly a couple python programs keep (zeromq) sockets open. This means I then have to manually find them (I use lsof -i), and kill them using the PID.
So I'm looking for an easier way of automatically killing those python processes from the shell when I hit ctrl+C. On another thread here on Stackoverflow I found some code which supposedly should do what I need. I just don't understand anything about the code and how I could adjust it to my needs.
Would anybody be so kind to help me out here?
cat >work.py <<'EOF'
import sys, time, signal
signal.signal(signal.SIGINT, signal.SIG_DFL)
for i in range(10):
time.sleep(1)
print "Tick from", sys.argv[1]
EOF
chmod +x work.py
function process {
python ./work.py $1
}
process one &
wait $!
echo "All done!"