Question: Two questions regarding Operating Systems Fork() code (in C) I want to know why the output is what it is? meaning why is the output
Two questions regarding Operating Systems Fork() code (in C) I want to know why the output is what it is? meaning why is the output 4 for both programs when i for fork3.c is i
Question 1) Fork3.c

code for fork3.c
#include
#include
#include
int main()
{
pid_t pid;
int x =0;
int i;
for (i =0; i
if((pid=fork())==0) // child process
break;
if (pid == 0 && i ==1)
fork();
x++;
printf("x = %d ",x);
sleep(10);
return 0;
}
Question 12) Fork2.c

code for fork2.c
#include
#include
#include
int main()
{
pid_t pid;
int x =0;
for (int i =0; i
if((pid=fork())==0) // child process,
break;
if (pid!=0) // parent process
for (int i=0;i
wait(NULL);
x++;
printf("x = %d ",x);
return 0;
}
#include
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
