title: How to create a process in C++ under Linux?
body: <p>I'd like to create a process by calling a executable, just as <code>popen</code> would allow. But I don't want to actually communicate through a pipe with it: I want to control it, like sending signals there or find out if the process is running, wait for it to finish after sending <code>SIGINT</code> and so on, just like <code>multiprocessing</code> in Python works. Like this:</p>
  
  <pre><code>pid_t A = create_process('foo');
  pid_t B = create_process('bar');
  
  join(B); // wait for B to return
  send_signal(A, SIGINT);
  </code></pre>
  
  <p>What's the proper way to go?</p>
  
  <p>Use case for example:</p>
  
  <ul>
  <li>monitoring a bunch of processes (like restarting them when they crash)</li>
  </ul>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I see in which direction the answers are going: <code>fork()</code>. Then I'd like to modify my use case: I'd like to create a class which takes a string in the constructor and is specified as follows: When an object is instantiated, a (sub)process is started (and controlled by the instance of the class), when the destructor is called, the process gets the terminate signal and the destructor returns as soon as the process returned.</p>
  
  <p>Use case now: In a boost state chart, start a process when a state is entered, and send termination when the state has been left. I guess, <a href="http://www.highscore.de/boost/process/process/tutorials.html#process.tutorials.start_child" rel="nofollow">http://www.highscore.de/boost/process/process/tutorials.html#process.tutorials.start_child</a> is the thing that comes closest to what I'm looking for, excpet that it seems outdated.</p>
  
  <p>Isn't that possible in a non-invasive way? Maybe I have a fundamental misunderstanding and there is a better way to do this kind of work, if so I'd be glad to get some hints.</p>
  
  <p><strong>UPDATE 2</strong></p>
  
  <p>Thanks to the answers below, I think I got the idea a little bit. I thought, this example would print "This is main" three times, once for the "parent", and once for each <code>fork()</code> – but that's wrong. So: Thank you for the patient answers!</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  
  #include &lt;unistd.h&gt;
  
  struct myclass
  {
      pid_t the_pid;
      myclass(std::string the_call)
      {
          the_pid = fork();
          if(the_pid == 0)
          {
              execl(the_call.c_str(), NULL);
          }
      }
  };
  
  int main( int argc, char** argv )
  {
      std::cout &lt;&lt; "This is main" &lt;&lt; std::endl;
      myclass("trivial_process");
      myclass("trivial_process");
  }
  </code></pre>