Bash script kill background (grand)children on Ctrl+C
I got it! All you have to do is get rid of that python SIGINT handler.
cat >work.py <<'EOF'import sys, time, signalsignal.signal(signal.SIGINT, signal.SIG_DFL)for i in range(10): time.sleep(1) print "Tick from", sys.argv[1]EOF chmod +x work.pyfunction process { python ./work.py $1}process one &wait $!echo "All done!"
Your trap
looks good to me:
$ bash --versionGNU bash, version 3.2.48(1)-release (x86_64-apple-darwin11)Copyright (C) 2007 Free Software Foundation, Inc.$ cat ./thang #! /bin/bashset -ecat >work.py <<EOFimport sys, timefor i in range(10): time.sleep(1) print "Tick from", sys.argv[1]EOFfunction process { python ./work.py $1 &}function killstuff { jobs -p | xargs kill}trap killstuff SIGINTprocess oneprocess twowait$ ./thang Tick from oneTick from twoTick from oneTick from two^C$ ps aux | grep python | grep -v grep$