title: How to Spawn Child Processes that Don't Die with Parent?
body: <p>I have a C++ program that acts as a watchdog over others. If it detects that a process is no longer running, it restarts it via <code>system</code>. The problem is, if I kill the watchdog process, any processes it has started up also die. </p>
  
  <pre><code>void* ProcessWatchdog::worker(void* arg)
  {
      //Check if process is running
      if( !processRunning )
          system("processName /path/to/processConfig.xml &amp;");
  }
  </code></pre>
  
  <p>The new child process gets started correctly, and runs without any  problems. But when the parent (now this <code>ProcessWatchdog</code> process) dies, the child dies too. How can I spawn a child process that is fully independent from the parent? </p>
  
  <p>I've tried using <code>pclose</code> and <code>popen</code>, running shell scripts that start processes, and a few other tactics, but to no avail. I'm ignoring <code>SIGHUP</code> signals in the child processes, but they still die. </p>
  
  <p>So ideally, I'd like to tell the system to start a process that is wholly independent from the parent. I want the child's <code>trace</code> to end with the child, and for it/the system to have no idea that <code>ProcessWatchdog</code> started it in the first place. </p>
  
  <p>Is there a way I can do this?</p>
  
  <p>I'm writing this in C++, on Linux.</p>