title: Nodejs detached child process killed when parent process is killed
body: <p>I'm on linux and I use a node process to spawn a child process which runs a bash script. The bash script does a dist-upgrade. Doing the dist-upgrade kills node, which kills the parent process, but also the upgrade itself.</p>
  
  <p>According to the nodejs docs a child process can keep running if the parent process exits, if the child process has been spawned with the <code>detached</code> flag.</p>
  
  <p>If I run this code:</p>
  
  <pre><code>const child_process = require("child_process");
  child_process.spawn('xterm', [], {
      detached: true,
      stdio: ['ignore','ignore','ignore']
  }).unref();
  </code></pre>
  
  <p>And when I kill the parent process in webstorm, the child process (xterm window) also exits... When I kill the parent using <code>kill -9/15/...</code> the child process keeps running. So it seems that some ways can still kill the child process if detached. But I don't know exactly when or why and how to avoid it?</p>