Question: void fork 1 () int x=1; pid t pid = fork (); if (pid== ) printf(Child has x=8d ,++x); else printf (Parent has x=8d ,x);

 void fork 1 () int x=1; pid t pid = fork(); if (pid== ) printf("Child has x=8d ",++x); else printf ("Parent has

void fork 1 () int x=1; pid t pid = fork (); if (pid== ) printf("Child has x=8d ",++x); else printf ("Parent has x=8d ",x); printf ("Bye from process od with x=%d ", getpid(), x); * Both processes continue/start execution after fork - Child starts at instruction after the call to fork (storing into pid) * Can't predict execution order of parent and child * Both processes start with x=1 - Subsequent changes to x are independent * Shared open files: stdout is the same in both parent and child Code 2: For each of the codes above, model the fork process with a process graph, essentially the tree of processes, capturing the partial ordering of statements in our current program (like what we did in our class demonstrations). Note that: - Each vertex is the execution of a statement - ab means a happens before b - Edges can be labeled with current value of variables - printf vertices can be labeled with output - Each graph begins with a vertex with no inedges Questions for each code: - How many processes have been created during the program execution? - What is the output of the program? - What are the concurrent processes as reflected in the process graph? - What are the sequential processes, if any

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!