title: work with fifo in c++ ( blocking read)
body: <p>What I want to do :</p>
  
  <p>1.Create and  open for writing in.fifo by process1</p>
  
  <p>2.Open in.fifo for reading in process2</p>
  
  <p>3.Write from cin to in.fifo by process1 line </p>
  
  <p>4.Read and cout line by process2 </p>
  
  <p>5.When input "exit" to cin (process2), it closed file in.fifo, delete it and exit</p>
  
  <p>6.process2 exit, because in.fifo has no writer </p>
  
  <p>In my programs process2 doesn't exit. In c it works with read,write when O_NONBLOCK is clear , but I want to do  it in c++</p>
  
  <p>write.cpp: </p>
  
  <pre><code>#include &lt;stdlib.h&gt;
  #include &lt;fstream&gt;
  #include &lt;string&gt;
  #include &lt;iostream&gt;
  using namespace std;
  int main(){
      std::ofstream fifo;
      fifo.open("/home/fedor/projects/fifo2/in",ios::out);
      if(! fifo.is_open() ){
          std::cout &lt;&lt; " error : cannot open file " &lt;&lt; std :: endl; 
          return 1;
      }
      std::cout &lt;&lt; " file open " &lt;&lt; std :: endl; 
      std::string   line;   
      while (line.compare("exit") != 0 ){
           std::getline(cin, line);
           fifo &lt;&lt; line &lt;&lt; endl;
            /* do stuff with line */
      }
      fifo.close();
      remove("/home/fedor/projects/fifo2/in");
      return 0;
  }
  </code></pre>
  
  <p>read.cpp:</p>
  
  <pre><code>#include &lt;stdlib.h&gt;
  #include &lt;fstream&gt;
  #include &lt;string&gt;
  #include &lt;iostream&gt;
  using namespace std;
  int main(){
      std::ifstream fifo;
      fifo.open("/home/fedor/projects/fifo2/in",ifstream::in);
          if(! fifo.is_open() ){
          std::cout &lt;&lt; " error : cannot open file " &lt;&lt; std :: endl; 
          return 1;
      }
      std::cout &lt;&lt; " file open " &lt;&lt; std :: endl; 
      std::string   line;
      bool done = false;
      while (!done)
          {
          while (std::getline(fifo, line))
          {
              cout &lt;&lt; line &lt;&lt; endl;
              /* do stuff with line */
          }
          if (fifo.eof())
          {
              fifo.clear();  // Clear the EOF bit to enable further reading
          }
          else
          {
              done = true;
          }
      }
      return 0;
  }
  </code></pre>
  
  <p>I can't find where I can read about blocking read by streams like <a href="http://linux.die.net/man/3/read" rel="nofollow">http://linux.die.net/man/3/read</a> about blocking read</p>
  
  <p>If process2 closed if input "exit", like process1 is that a life lock ? (Is it blocking on read, or just trying and trying to read ) </p>