title: Simulate Ctrl-C keyboard interrupt in Python while working in Linux
body: <p>I am working on some scripts (in the company I work in) that are loaded/unloaded into hypervisors to fire a piece of code when an event occurs. The only way to actually unload a script is to hit <kbd>Ctrl</kbd>-<kbd>C</kbd>. I am writing a function in Python that automates the process</p>
  
  <p>As soon as it sees the string <code>"done"</code> in the output of the program, it should kill the <code>vprobe</code>.
  I am using <code>subprocess.Popen</code> to execute the command:</p>
  
  <pre><code>lineList = buff.readlines()
  cmd = "vprobe /vprobe/myhello.emt"
  p = subprocess.Popen(args = cmd, shell=True,stdout = buff, universal_newlines = True,preexec_fn=os.setsid)
  while not re.search("done",lineList[-1]):
          print "waiting"
  os.kill(p.pid,signal.CTRL_C_EVENT)
  </code></pre>
  
  <p>As you can see, I am writing the output in <code>buff</code> file descriptor opened in read+write mode. I check the last line; if it has <code>'done'</code>, I kill it. Unfortunately, the <code>CTRL_C_EVENT</code> is only valid for Windows.
  What can I do for Linux?</p>