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

Two questions regarding Operating Systems Fork() code (in C) I want to

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

know why the output is what it is? meaning why is the

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 Fork3 #include 4 5 int main() pid t pid; int x 0; 10 for (i i -e; if ((pid-fork))--0) / child process 2; i++) 12 13 14 15 16 17 18 19 20 break; fork); printf("X %d ",x); sleep(10); return 0 Input Goes Here Time(sec): 0 Memor utput x1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!