title: Segmentation fault when i run two process with fork
body: <p>When I run this program :</p>
  
  <pre><code>#include &lt;sys/types.h&gt;
  #include &lt;pthread.h&gt;
  #include &lt;sys/mman.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;fcntl.h&gt;
  #include &lt;sys/stat.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;sys/wait.h&gt;
  #include &lt;stdlib.h&gt;
  
  int main () {
  
      int stat;
  
      pthread_mutex_t *mutex = (pthread_mutex_t*)mmap (0, sizeof (pthread_mutex_t) + sizeof (long),PROT_READ | PROT_WRITE,
                                                       MAP_SHARED ,-1, 0);
  
      long *data = (long*)(&amp;mutex[1]); /* map 'data' after mutex */
      int pid;
  
      pthread_mutexattr_t attr;
      pthread_mutexattr_init (&amp;attr);
      pthread_mutexattr_setpshared (&amp;attr, PTHREAD_PROCESS_SHARED);
      pthread_mutex_init (mutex, &amp;attr);
  
      *data = 0;
  
      pid = fork ();
  
      pthread_mutex_lock (mutex);
      (*data)++;
      pthread_mutex_unlock (mutex);
  
      if (!pid) /* child exits */
          exit (0);
      else
          waitpid (pid, &amp;stat, 0);
      printf ("data is %ld\n", *data);
  
      return 0;
  }
  </code></pre>
  
  <p>I have <code>segmentation fault</code> ! What is problem please ? and what can i do to resolve this error ?</p>
  
  <p>after debbuging with <code>valgrind</code>, i have this message : </p>
  
  <pre><code>==28660== Process terminating with default action of signal 11 (SIGSEGV)
  ==28660==  Access not within mapped region at address 0xF
  ==28660==    at 0x4E35C10: pthread_mutex_init (pthread_mutex_init.c:83)
  ==28660==    by 0x4008F0: main (in /home/program)
  ==28660==  If you believe this happened as a result of a stack
  ==28660==  overflow in your program's main thread (unlikely but
  ==28660==  possible), you can try to increase the size of the
  ==28660==  main thread stack using the --main-stacksize= flag.
  ==28660==  The main thread stack size used in this run was 8388608.
  </code></pre>