title: Check for a broken pipe before trying to write to it?
body: <p>Is it possible to check if a pipe is broken before trying to write/read to it, so I can just skip it and continue with the program?</p>
  
  <p>I'm utilizing a <code>while</code> loop to write to pipes communicating from the Parent to multiple Children.  Over the course of the loop, several of the children will close.  When the loop comes around and tries to write to them again, my program shuts down because it is killed by SIGPIPE since the pipe is broken.  I know the pipe is broken, I programmed the children to close their pipes and exit (necessary).  I still want to finish the loop and move on with the program.  I'd like it to check if the pipe is broken, skip over it if broken (without an error output), and move on with the program (the other children still need to be written to).</p>
  
  <p>So, is it possible? An example in c would be great.</p>
  
  <p>Here's a simple pseudocode representation of what I'm asking:</p>
  
  <pre><code>int i = 0;
  
  while(i != 5)
  {
      if (mypipe[WRITE] is BROKEN)
          //Do Nothing ---Basically Skip
  
      else if (some condition)
          write(mypipe[WRITE]);
  
      i++;
  }
  </code></pre>
  
  <p>This question is related to a <a href="https://stackoverflow.com/questions/26331975/proper-fork-and-pipe-use-for-a-single-parent-having-multiple-children-how-d">previous post</a> of mine, though the context of my question is different.  You can review the code for the actual program there.</p>