title: How to share semaphores between processes using shared memory
body: <p>I have to synchronize N client processes with one server. These processes are forked by a main function in which I declared 3 semaphores. I decided to use POSIX semaphores but I don't know how to share them between these processes. I thought that shared memory should work correctly, but I have some questions: </p>
  
  <ul>
  <li>How can I allocate the right space of memory in my segment? </li>
  <li>Can I use <code>sizeof(sem_t)</code> in <code>size_t</code> field of <code>shmget</code> in order to allocate exactly the space I need? </li>
  <li>Does anyone have some examples similar to this situation? </li>
  </ul>