GATE - 2005 | OS | Consider the following code fragment if (fork() == 0)

GATE - 2005 | OS | Consider the following code fragment if (fork() == 0)
Posted on 19-02-2022

GATE - 2005 [Operating System]

Question:

Consider the following code fragment:

  if (fork() == 0)

  { a = a + 5; printf(“%d,%dn”, a, &a); }

  else { a = a –5; printf(“%d, %dn”, 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?

A

u = x + 10 and v = y

B

u = x + 10 and v is ≠ y

C

u + 10 = x and v = y

D

u + 10 = x and v ≠ y

     

Solution:

Option (C) is Correct.

u, v values printed by parent process.
u=a-5; v be address of a
a=u+5;
x, y values printed by child process.
x=a+5; y be the address of a
x=u+5+5; v=y
x=u+10