edited by
37,287 views
123 votes
123 votes
Consider the following code fragment:
if (fork() == 0)
{
   a = a + 5;
   printf("%d, %p n", a, &a);
}
else
{
   a = a - 5;
   printf ("%d, %p 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  \text{ and } v = y$
  2. $u = x + 10 \text{ and } v != y$
  3. $u + 10 = x \text{ and } v = y$
  4. $u + 10 = x \text{ and } v != y$
edited by

9 Answers

2 votes
2 votes
$u, v$ values printed by the parent process.
$u=a-5; v$ be address of $a$
$a=u+5;$
$x, y$ values printed by the child process.
$x=a+5; y$ be the address of $a$
$x=u+5+5; v=y$
$x=u+10$
edited by
0 votes
0 votes
Child will execute else part as it will be if(0) so it will be a-5 , parent will execute if part as it will be if(>0) so it will be a+5 so u = x+10 ...by fork call parent and child will have identical address space so v =y so answer is C
edited by
Answer:

Related questions

35 votes
35 votes
2 answers
4
Kathleen asked Sep 22, 2014
41,902 views
Increasing the RAM of a computer typically improves performance because:Virtual Memory increasesLarger RAMs are fasterFewer page faults occurFewer segmentation faults occ...