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 http://u.cs.biu.ac.il/~linraz/os/OS2.pdf, http://www.ibm.com/developerworks/aix/library/au-unixprocess.html , Who executes first after fork(): parent or the child? . But, I couldn't find the solution. It would be of great help if somebody helps me to understand this problem.
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
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;
}