title: what happens to pointers to dynamically allocated memory after a UNIX fork?
body: <p>Someone please clarify what happens with pointers after a fork(). </p>
  
  <p>As I understand it, pointers to anything on the stack or statically allocated are relative to the stack/data segment registers, so copying them exactly during a fork is OK.</p>
  
  <p>However, what happens if I malloc() something before forking? for example:</p>
  
  <pre><code>void* p = malloc(64);
  // put something in *p;
  fork();
  
  // what happens to p and the memory i allocated here?
  </code></pre>
  
  <p>possibilities I am thinking of:</p>
  
  <ol>
  <li><p>*p is copied to some other part of the heap, p is updated to reflect the newly copied location.</p></li>
  <li><p>p still points to the original. if any child runs free(p); the parent may be unable to access it.</p></li>
  <li><p>p still points to the original data, but the child process does not have rights to access/manage the memory.</p></li>
  </ol>
  
  <p>which of these, if any, is correct?</p>