title: Shmat with non-null shmaddr
body: <p>Could someone provide an example of (reasonably) using the function shmat() with non-null second parameter?</p>
  <p>The manual says:</p>
  <blockquote>
  <p><code>#include &lt;sys/shm.h&gt;</code></p>
  <p><code>void *shmat(int shmid, const void *shmaddr, int shmflg);</code></p>
  <p>The shmat() function attaches the shared memory segment associated with the shared memory identifier shmid to the data segment of the calling process. The segment is attached at the address specified by one of the following criteria:</p>
  <ul>
  <li>If <code>shmaddr</code> is a NULL pointer, the segment is attached at the first available address as selected by the system.</li>
  <li>If <code>shmaddr</code> is not a NULL pointer and (shmflg &amp; SHM_RND) is non-zero, the segment is attached at the address given by (shmaddr - (shmaddr % SHMLBA)).</li>
  <li>If <code>shmaddr</code> is not a NULL pointer and (shmflg &amp; SHM_RND) is 0, the segment is attached at the address given by shmaddr.</li>
  </ul>
  </blockquote>
  <p>but I have never seen any example of shmat used with anything but shmaddr set to NULL. In my project, a process got to attach it to a <code>malloc()</code>'ed piece of memory just okay, and could use it just fine, then another process acquired the pointer to that shared memory (by shmid), then segfaulted while trying to access the memory.</p>