edited by
36,949 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

0 votes
0 votes
  • So these virtual addresses are translations of physical addresses and doesn't represent the same physical memory space, to leave a more practical example we can do a test, if we compile and run multiple times a program that displays the direction of a static variable, such as this program.

    #include <stdio.h>
    
    int main()
    {
    static int a = 0;
    
    printf("%p\n", &a);
    
    getchar();
    
    return 0;
    }

    It would be impossible to obtain the same memory address in two different programs if we deal with the physical memory directly.

    And the results obtained from running the program several times are...

enter image description here

 

 

Source : Stackoverflow.

 

Answer:

Related questions

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