title: How to share memory between processes created by fork()?
body: <p>In fork child, if we modify a global variable, it will not get changed in the main program.</p>
  
  <p>Is there a way to change a global variable in child fork?</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;unistd.h&gt;
  
  int glob_var;
  
  main (int ac, char **av)
  {
    int pid;
  
    glob_var = 1;
  
    if ((pid = fork()) == 0) {
      /* child */
      glob_var = 5;
    }
    else {
      /* Error */
      perror ("fork");
      exit (1);
    }
  
    int status;
    while (wait(&amp;status) != pid) {
    }
     printf("%d\n",glob_var); // this will display 1 and not 5.
  }
  </code></pre>