Skip to content

Instantly share code, notes, and snippets.

@bhavul bhavul/fork2.cpp
Created Jun 18, 2017

Embed
What would you like to do?
#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
You can’t perform that action at this time.