title: How to kill all processes that were opened by a shell script upon ctrl + C?
body: <p>I've got a couple python scripts which I start collectively from a shell script as follows:</p>
  
  <pre><code>#!/bin/bash
  python prog1.py &amp;
  python prog2.py &amp;
  python prog3.py 
  </code></pre>
  
  <p>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 <em>lsof -i</em>), and kill them using the PID.</p>
  
  <p>So I'm looking for an easier way of automatically killing those python processes from the shell when I hit ctrl+C. On <a href="https://stackoverflow.com/questions/11696691/bash-script-kill-background-grandchildren-on-ctrlc">another thread here on Stackoverflow</a> 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.</p>
  
  <p>Would anybody be so kind to help me out here?</p>
  
  <pre><code>cat &gt;work.py &lt;&lt;'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 &amp;
  wait $!
  echo "All done!"
  </code></pre>