I am using the following code for a fork execution
#include <stdio.h>
#include <sys/types.h>
int main()
{
int pid;
pid=fork();
if(pid==0)
{
printf("\n child 1");
pid=fork();
if (pid==0)
printf("\n child 2");
}
return 0;
}
The output I assume should be child1 child2
Instead I am getting
child1 child2 child1
Cannot understand the fork behaviour