0

Bellow is the code of what is going on , and here is an image of what am i trying to do , any help would be appreciated.Trying to draw the diagram of all the processes Code:

for(i=0;i<2;i++){
  int pid = fork();
    if(pid == 0){
        fork();
    printf("\tA\n");
    }
    else{
        printf("\tB\n");
    }
}//for
printf("\tC\n");
return 0;

}

This is the code of the program

This is the output of the program

Ivan
  • 1
  • 2

1 Answers1

1

Mainly missing from your diagram is in the block Child1 as well as Child1.1 a second run through the for loop, since these children are still inside the loop and their i is initially also 0.
On the other hand, the C=3 in Parent is wrong because C is only printed once at the end, not in the loop.

Armali
  • 18,255
  • 14
  • 57
  • 171
  • 1
    Thank you that was very helpful , it's an image not a screen shot my bad firstly i created a diagram online i took a screenshot but it was not clear. Thanks again have a good day! – Ivan Apr 05 '21 at 03:21