//Program 1 main () {int vai =5; main() {int child = forkO; int x = 5; if (child
ID: 3798892 • Letter: #
Question
//Program 1 main () {int vai =5; main() {int child = forkO; int x = 5; if (child == 0) {x +- 5; > else {child = for kO; x +- 10; if (child) {x+=5; >)} How many different copies of the variable x are there? What are their values when their process finishes? if (fork() > 0) {wait(&val;); vai - WEXITSTATUS(val);} val++; printf(*%d *, val); return val;}//Program 2 main () {int vai -5; if (fork () > 0) {wait(&vai;); vai - EXITSTATUS(val);} else exit (val); val++; printf(*%d ", val); return val; > Consider the following C program. # include main () {Here is a description of the return value of wait O from the corresponding UNIX manage: her. Wait () returns due to a terminated child process, the process 2D of the child is returned to the calling process. Otherwise, -1 is returned and errro is set to indicate the error. int pid; pid - forkO; if(pid == 0) fork (); forkO; orintf("I'n a process:) ");) many processes are created when you run the above program? Draw a apt that establishes the parent child relationships among the processes. Each ocess should be represented by a node and a parent child relationship by a reacted edge from the parent to the child. What is the output of the following two programs? The wait () function will fail if: ECKILO the calling process has no existing unwanted-for child processes.Explanation / Answer
(1)The program creates two processes.Therefore, we have a total of three different copies, the parent, the first and second child.
Each of these has its own private copy of the variable c.
a.For the parent, the variable x be 20 before the end of the program.
b.For the first child the variable x will contain the value 10 before the end of the program.
c.For the second child i.e, created in the else clause, the variable x will contain the value 15 before the end of the program.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.