I am trying to write a program which will create processes as follows :
P1 -> P2 -> P3
P1-> P4 ->P5
P2, P3 need to be finished before P4, P5
my code so far :
#include<stdio.h>
int main()
{
for(int i=0;i<2;i++) // loop will run 2 times
{
if(fork() == 0)
{
printf("[son] pid %d from [parent] pid %d\n",getpid(),getppid());
exit(0);
}
}
for(int i=0;i<2;i++) // loop will run 2 times
wait(NULL);
}
I am facing difficulties in running P4 and P5 after P2,P3 if they are forked from P1. Kindly help