title: How to pick up SIGINT signal from Emacs in Perl script?
body: <p>I am trying to run Emacs as a foreground process in the terminal window using a Perl <code>system</code> call. I would like to terminate both Emacs and the Perl script when I press <code>CTRL-C</code> in the terminal window. However, only the Emacs command terminates. Here is an example script <code>test.pl</code>:</p>
  
  <pre><code>#! /usr/bin/env perl
  use strict;
  use warnings;
  
  my $cmd = shift;
  
  for ( my $i = 1; $i &lt;= 3; $i ++) {
      my $res = system ($cmd);
      if ( $res == -1 ) {
          die "Failed to execute '$cmd': $!\n";
      }
      my $signal = ($? &amp; 127);
      my $exit_code = ($? &gt;&gt; 8);
      print "exit_code = $exit_code, signal = $signal\n";
      if ( $signal ) {
          die "Command '$cmd' died with signal $signal\n";
      }
  }
  </code></pre>
  
  <p>The output of </p>
  
  <pre><code>$ test.pl 'emacs file.txt'
  </code></pre>
  
  <p>is (after pressing <code>CTRL-C</code> three times):</p>
  
  <blockquote>
    <p>^Cexit_code = 0, signal = 0<br>
    ^Cexit_code = 0, signal = 0<br>
    ^Cexit_code = 0, signal = 0</p>
  </blockquote>
  
  <p>So Emacs is terminated, but the Perl script keeps running.. 
  However, if I run </p>
  
  <pre><code>$ test.pl 'sleep 10'
  </code></pre>
  
  <p>I get output:</p>
  
  <blockquote>
    <p>^Cexit_code = 0, signal = 2<br>
    Command 'sleep 10' died with signal 2</p>
  </blockquote>
  
  <p>So if I run <code>sleep 10</code> instead of <code>emacs file.txt</code> it works fine.</p>