Tuesday, 19 November 2013

PROCESS TREE USING FORK


PROGRAM

      
#include<unistd.h>
void main()
{
int pid;
pid= fork();
if(pid==0)
{
printf(“Child 1 ID : %d \n Parent ID of Child 1 : %d”, getpid(),getppid());
pid=fork();
if(pid==0)
{
printf(“\n Child 3 ID : %d \n Parent  ID of Child 3 : %d”,getpid(),getppid());
close(getpid());
}
else
{
pid= fork();
if(pid==0)
{
printf(“ \n Child 4 ID : %d \t Parent ID  of Child 4 : %d”, getpid(),getppid());
close(getpid());
}
else
{
sleep(1);
}
}
}
else
{
pid= fork();
if(pid==0)
{
printf(“  \n Child 2 ID : %d \t Parent ID  of Child 2: %d”, getpid(),getppid());
pid=fork();
if(pid==0)
{
printf(“\n Child 5 ID : %d \n Parent  ID of Child 5 : %d”,getpid(),getppid());
close(getpid());
}
else
{
pid= fork();
if(pid==0)
{
printf(“ \n Child 6 ID : %d \t Parent ID  of Child 6 : %d”, getpid(),getppid());
close(getpid());
}
else                                                                          
{
sleep(2);
}
}
}
}
sleep(3);
}

DESCRIPTION AND OUTPUT WILL BE PUBLISHED ............


0 Comments:

Post a Comment

Facebook Twitter Delicious Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | coupon codes