title: Why there are many PIDs printed while using fork system call?
body: <p>I am learning the process management in Linux and I tried implementing the following C program, the output of which printed 15 PIDs(4 unique PIDs). I tried to figure out the process family tree but it really didnt help me understand why the PIDs were printed so many times. I went through few links including <a href="http://u.cs.biu.ac.il/~linraz/os/OS2.pdf" rel="nofollow noreferrer">http://u.cs.biu.ac.il/~linraz/os/OS2.pdf</a>, <a href="http://www.ibm.com/developerworks/aix/library/au-unixprocess.html" rel="nofollow noreferrer">http://www.ibm.com/developerworks/aix/library/au-unixprocess.html</a> , <a href="https://stackoverflow.com/questions/8494732/who-executes-first-after-fork-parent-or-the-child">Who executes first after fork(): parent or the child?</a> . But, I couldn't find the solution. It would be of great help if somebody helps me to understand this problem.</p>
  
  <pre><code>    #include &lt;stdio.h&gt;
      #include &lt;unistd.h&gt;
      #include &lt;sys/types.h&gt;
  
      int main()
      {
             printf ( "Parent:%d Child: %d\n",getppid(),getpid()); // To print the PIDs of the parent process and the child process
             fork();               //System call to spawn a child process
             printf ( "Parent:%d Child: %d\n",getppid(),getpid()); 
             fork();
             printf ( "Parent:%d Child: %d\n",getppid(),getpid());
             fork();
             printf ( "Parent:%d Child: %d\n",getppid(),getpid());
             return 0;
      }
  </code></pre>