title: Using shared memory and semaphores with multiple clients
body: <p>I'm working with C on Linux. I need to build two programs that communicate using shared memory and semaphores.</p>
  
  <p>One of the programs must serve as a server (only one at a time) and the other as a client (any number at a time). The communication should follow this pattern:  </p>
  
  <pre><code> Client1 -&gt; Server (Client1 writes to ShM, Server reads it)  
   Client1 &lt;- Server  
   Client2 -&gt; Server  
   Client2 &lt;- Server  
  </code></pre>
  
  <p>I know how to use shared memory and semaphores between two processes but I don't know how to use them if an undefined number of processes want to communicate.
  I thought about using a shared memory block for each client but i would have to exchange keys and notify the server of a new client. So this doesn't solve the problem.</p>