#include<stdio.h>
#include<string.h>
#include<stdlib.h>
main()
{
if(fork())
{
//system("date");
printf("parent=%d bash=%d\n",getpid(),getppid());
if(fork())
{
// system("cal");
printf("parent=%d bash=%d\n",getpid(),getppid());
if(fork())
{
printf("parent=%d bash=%d\n",getpid(),getppid());
if(fork())
printf("parent=%d bash=%d\n",getpid(),getppid());
else
printf("in process3 child3=%d parent= %d...\n",getpid(),getppid());
}
else
printf("in process2 child2= %d parent=%d...\n",getpid(),getppid());
}
else
printf("in process1 child1= %d parent=%d...\n",getpid(),getppid());
}
}
OutPut:
madan@madan-Lenovo-G570:~/madan/osconcepts$ cc ex32.c
madan@madan-Lenovo-G570:~/madan/osconcepts$ ./a.out
parent=5464 bash=2817
parent=5464 bash=2817
in process1 child1= 5466 parent=5464...
parent=5464 bash=2817
parent=5464 bash=2817
in process2 child2= 5467 parent=5464...
in process3 child3=5468 parent= 1144...