Skip to content

Instantly share code, notes, and snippets.

@bhavul
Created June 18, 2017 07:24
Show Gist options
  • Save bhavul/4350799e41ef2f023f80e3d44474949d to your computer and use it in GitHub Desktop.
Save bhavul/4350799e41ef2f023f80e3d44474949d to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
int main()
{
if(fork()) //1st child p2 created
{
printf("after first fork. pid : %d\n", getpid());
if(fork()) //2nd child p3 created
{
printf("after second fork, pid: %d\n", getpid());
fork(); //3rd child p4 created
printf("after third fork, pid: %d\n", getpid());
}
printf("getting out of if, pid: %d\n", getpid());
}
printf("outermost, pid: %d\n", getpid());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment