title: Difference between the address space of parent process and its child process in Linux?
body: <p>I am confused about something. I have read that when a child is created by a parent process, the child gets a copy of its parent's address space. What does it mean by copy?
  If I use the code below, then it prints the same value for variable 'a' which is on the heap in both tthe child and parent. So what is happening here?</p>
  <pre class="lang-c prettyprint-override"><code>int main ()
  {
          pid_t pid;
          int *a = (int *)malloc(4);
          printf (&quot;heap pointer %p\n&quot;, a);
          pid = fork();
          if (pid &lt; 0) {
                  fprintf (stderr, &quot;Fork Failed&quot;);
                  exit(-1);
          }
          else if (pid == 0) {
                  printf (&quot;Child\n&quot;);
                  printf (&quot;in child heap pointer %p\n&quot;, a);
          }
          else {
  
                  wait (NULL);
                  printf (&quot;Child Complete\n&quot;);
                  printf (&quot;in parent heap pointer %p\n&quot;, a);
                  exit(0);
          }
  }
  </code></pre>