title: Node child processes: how to intercept signals like SIGINT
body: <p>In my Node app, I'm hooking on the <code>SIGINT</code> signal in order to gracefully stop (using <code>pm2</code>, but this is not relevant here).</p>
  
  <p>My app also execs/spawns a couple of child processes.</p>
  
  <p>I am able to hook on <code>SIGINT</code> to intercept it and perform graceful stop, <em>however</em> my child processes are passed through the same signal, and thus, instantly killed.</p>
  
  <p>How can I intercept the <code>SIGINT</code> signal on my child processes?</p>
  
  <p>A sample of what I'm doing:</p>
  
  <pre><code>const child = child_process.spawn('sleep', ['10000000']);
  console.log(`Child pid: ${child.pid}`);
  
  child.on('exit', (code, signal) =&gt; { console.log('Exit', code, signal); });
  
  process.on('SIGINT', () =&gt; {
      console.log("Intercepting SIGINT");
  });
  </code></pre>