Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started