title: fork mulitple child in one parent
body: <p>I want to fork three child process in one parent.
  And the following is my C++ code:</p>
  
  <pre><code>#include &lt;unistd.h&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;sys/wait.h&gt;
  #include &lt;iostream&gt;
  
  using namespace std;
  
  int main()
  {
      pid_t pid;
      for (int i = 0; i &lt; 3; i++)
      {
          pid = fork();
  
          if (pid &lt; 0)
          {
              cout &lt;&lt; "Fork Error";
              return -1;
          }
          else if (pid == 0)
              cout &lt;&lt; "Child " &lt;&lt; getpid() &lt;&lt; endl;
          else
          {
              wait(NULL);
              cout &lt;&lt; "Parent " &lt;&lt; getpid() &lt;&lt; endl;
              return 0;
          }
      }
  }
  </code></pre>
  
  <p>Now my output is :</p>
  
  <pre><code>Child 27463
  Child 27464
  Child 27465
  Parent 27464
  Parent 27463
  Parent 27462
  </code></pre>
  
  <p>How should I modify my program to get the output like the following?</p>
  
  <pre><code>Child 27463
  Child 27464
  Child 27465
  Parent 27462
  </code></pre>
  
  <p>What I mean is that these THREE children need to belong to the same ONE parent, can anybody give me some suggestion ?</p>
  
  <p>Thank you all. :)</p>