title: What is the difference between Ctrl-C and SIGINT?
body: <p>I have been debugging a Python program which segfaults after receiving a <code>KeyboardInterrupt</code> exception. This is normally done by pressing <kbd>Ctrl+C</kbd> from the shell. To test if a particular code change fixed the bug, I had a small shell-script that sent <code>SIGINT</code> to the program at random time after start-up. The problem I have is that sending <kbd>Ctrl+C</kbd> seems to have a different effect on the program than sending the signal <code>SIGINT</code> and is thus not causing the bug to appear, so I quite wonder what the difference is then between the two actions.</p>
  
  <p>The program does not catch any keyboard actions at all, and is just a python program with some threads/processes in them. It installs no signal handlers (though Python does), and <code>stty -a</code> gives <code>intr = ^C</code>. I suspect it might be that <kbd>Ctrl+C</kbd> sends <code>SIGINT</code> to all the sub-processes/threads while <code>kill -INT</code> only sends to the primary process, but that is as far my suspicions go.</p>
  
  <p>Here is the shell script which sends the <code>kill -INT</code>.</p>
  
  <pre class="lang-sh prettyprint-override"><code>wait
  while :; do
      seconds="$(python -c 'import random; print random.random()*4')"
      ./mandos --debug --configdir=confdir \
               --statedir=statedir --no-restore --no-dbus &amp;
      pid=$!
      { sleep $seconds; kill -INT $pid; } &amp;
      fg %./mandos
      status=$?
      if [ $status -gt 1 ]; then
          echo "Failed exit $status after $seconds seconds"
          break
      fi
      wait
  done
  </code></pre>