Multiple choice

Consider the following code fragment: if (fork()==0 {a = a + 5; print f (%d,%/na, and a);} else {a − 5; print f (%d,%d/n,a,&a);} Let u, v be the values printed by the parent process, and x,y be the values printed by the child process. Which one of the following is TRUE?

  1. u = x + 10 and v = y

  2. u = x + 10 and v $\ne$ y
  3. u + 10= x and v = y

  4. u + 10 = x and v $\ne$ y
Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

Initial value of a is 10 and its address and the value of 'a' would be different for both the parent and child processes. So, (1) and (2) are incorrect. Also, parent process executes a = a − 5 = 5 = u and child executes a = a + 5 = 15 = x. Therefore, u + 10 = x.