title: Multiple child processes reading/writing on the same pipe
body: <p>I am currently learning sockets programming using C in a Linux environment. As a project I am attempting to write a basic chat server and client. </p>
  
  <p>The intention is to have the server fork a process for each client that connects. </p>
  
  <p>The problem that I am having is reading data in one child and writing it to all of the connected clients. </p>
  
  <p>I have tried to accomplish this by looping on a call to select in the child that waits for data to arrive on the socket or read end of the pipe. If it arrives on the socket the idea is that it writes to the write end of the pipe which causes select to return the read end of the pipe as ready for reading.</p>
  
  <p>As this pipe is shared between all the children, each child should then read the data on the pipe. This does not work as the data pipe, it appears, cannot be read by each child process at the same time and the children that "miss" the data block in the call to read. </p>
  
  <p>Below is the code in the child process that does this:</p>
  
  <pre><code>for( ; ; )
  {
    rset = mset;
    if(select(maxfd+1, &amp;rset, NULL, NULL, NULL) &gt; 0)
    {
      if(FD_ISSET(clientfd, &amp;rset))
      {
        read(clientfd, buf, sizeof(buf));
        write(pipes[1], buf, strlen(buf));
      }
      if(FD_ISSET(pipes[0], &amp;rset))
      {
        read(pipes[0], buf, sizeof(buf));
        write(clientfd, buf, sizeof(buf));
      }
    }
  }
  </code></pre>
  
  <p>I am presuming the method that I am currently using simply will not work. Is it going to be possible for messages received from a client to be written to all of the other connected clients via IPC?</p>
  
  <p>Thanks</p>