title: Why is read() not blocking or Why is my write() sending blanks?
body: <p><strong>This is for HW</strong> A little background on my project. I am writing a client/server program. My client is to spawn my server process and then send a filename and search term to the server through a named pipe. My server is to search the file for instances of the search term and send back that it was found. It is working fine until my last two lines. After searching the whole file, the server is to tell the client the total times the search term was found. The client will then output this information in a specially formatted line. In order to tell my client that it's time for that special "total" line, I am having my server send "last line". Client should retrieve that from the pipe, go into a conditional statement to handle the special line, and then grab from the pipe the overall total from the server. </p>
  
  <p>Here is my issue: my Client is recognizing the "last line" input and going into the correct conditional statement, but when It goes to grab the overall total from the pipe it always comes back blank. If there was nothing in the pipe, shouldn't it block? If that isn't the problem, why/how are blanks getting into the pipe? I have a statement proving that the overall total is getting into the pipe</p>
  
  <p>client: </p>
  
  <pre><code>...
  char endMessage[] ="Server-EOF";
          read(fd2, buffer, maxBufferSize);
  
  
          while(strcmp(buffer,endMessage) != 0)
          {       
  
                  if(strcmp(buffer, "final line") ==0)
                  {
                          read(fd2, buffer, maxBufferSize);
                          cout &lt;&lt;"final line buffer is:&lt;&lt; buffer &lt;&lt; endl;
                          cout &lt;&lt;"Client : PID " &lt;&lt;clientPID &lt;&lt; "- Target &gt;&gt;"&lt;&lt; requestedTarget
                                  &lt;&lt;"&lt;&lt; in File &gt;&gt;" &lt;&lt;requestedFileName&lt;&lt; "&lt;&lt; " &lt;&lt; buffer &lt;&lt;endl;
                  }
                  else{
  
                  cout &lt;&lt; "Client :PID " &lt;&lt; clientPID &lt;&lt;" - Target &gt;&gt;" &lt;&lt;requestedTarget
                          &lt;&lt;"&lt;&lt; " &lt;&lt; buffer &lt;&lt; endl;
                  }
  
                  read(fd2, buffer, maxBufferSize);
          }
  </code></pre>
  
  <p>server:</p>
  
  <pre><code> size_t found;
      getline(rf,tempLine);
      while (!rf.eof())
      {
          currentLineNumber++;
  
              found= tempLine.find(requestedTarget);
              while(found != string::npos)
              {
                      totalTimesFoundInFile++;
                      totalTimesFoundOnLine++;
                      found=tempLine.find(requestedTarget, found+1);
              }
  
  
  
              if(totalTimesFoundOnLine != 0)
              {
                      int n = sprintf(stringToSend, "Appeared on Line %d,     %d times",currentLineNumber,
                                      totalTimesFoundOnLine);
                      write(fd2, stringToSend, sizeof(stringToSend));
  
              }
  
              getline(rf,tempLine);
              totalTimesFoundOnLine = 0;
  
      }
      int t = sprintf(stringToSend, "Appeared a Total of %d Times",totalTimesFoundInFile);
      cout &lt;&lt;"Final string to send: " &lt;&lt; stringToSend &lt;&lt;endl;
      char finalLine[] = "final line";
      write(fd2, finalLine, sizeof(finalLine));
      cout &lt;&lt;"Just put 'finalLine' into pipe" &lt;&lt;endl;
      write(fd2, stringToSend, sizeof(stringToSend));
      cout &lt;&lt;"Just put final string into pipe" &lt;&lt;endl;
  
  
  
      char endingMessage[]="Server-EOF";
      write(fd2, endingMessage, sizeof(endingMessage));
  </code></pre>
  
  <p>output:</p>
  
  <pre><code>Final string to send: Appeared a Total of 4 Times
  Just put 'finalLine' into pipe
  Just put final string into pipe
  Client :PID 12684 - Target &gt;&gt;apple&lt;&lt; Appeared on Line 1,        1 times
  Client :PID 12684 - Target &gt;&gt;apple&lt;&lt; Appeared on Line 2,        1 times
  Client :PID 12684 - Target &gt;&gt;apple&lt;&lt; Appeared on Line 4,        2 times
  final line Buffer is:
  Client : PID 12684- Target &gt;&gt;apple&lt;&lt; in File &gt;&gt;pipedTest.txt&lt;&lt;
  </code></pre>
  
  <p>I tried to edit out things that were irrelevant, but if there is any clarification needed, I'll be watching this thread closely for a bit.</p>
  
  <p><strong>EDIT</strong> I did some checking and it looks like my server is getting all of the way through its code and returning. Could that be the issue? Does that close/clear the pipe? If so, is there a way to get my server to wait on my client before returning?</p>