title: Named pipes - Problem with write() and read()
body: <p>I am doing programming in C++, under LINUX.
  I have two independent processes. I should provide communication using named pipe. </p>
  
  <p>Reader:
  -creates FIFO using mkfifo - status = mkfifo(myFIFO, 0666) 
  -opens the pipe using open - fifo = open (myFIFO,O_RDONLY)
  -reads from the pipe - num = read(fifo, temp, sizeof(temp))</p>
  
  <p>Writer:
  -opens pipe - fifo = open(myFIFO, O_WRONLY);
  -writes to the pipe - num = write(fifo, string, strlen(string));</p>
  
  <p>I have noticed that the file descriptor returned for read process 
  and write process are 0. Also, after command write, I can see on my terminal, the string which should be written to the pipe. I don't know why it is shown on terminal... Also, the number of bytes that are written is 0... </p>
  
  <p>Would you please help me?
  Thank you!!!</p>
  
  <pre><code>// read.cpp:
  
  #define myFIFO "/temp/FIFO"
  
  int main(){
      int num, fifo, status;
      char temp[32];
  
      if (status = mkfifo(myFIFO, 0666) &lt; 0) { 
       printf("\n %s \n", strerror(errno));
       return 0;
       }
  
       if (fifo = open(myFIFO, O_RDONLY) &lt; 0) { 
       printf("\n %s \n", strerror(errno));
       return 0;
       }
  
       if (num= read(fifo, temp, sizeof(temp)) &lt; 0) { 
       printf("\n %s \n", strerror(errno));
       return 0;
       }
  
      printf("In FIFO is %s \n", temp);
  }
  </code></pre>
  
  <p>And in another file:</p>
  
  <pre><code>// write.cpp:
  
  #define myFIFO "/temp/FIFO"
  
  int main() {
      int status, num, fifo;
      char string[]="Testing...";
  
       if (fifo = open(myFIFO, O_WRONLY) &lt; 0) { 
       printf("\n %s \n", strerror(errno));
       return 0;
       }
  
       if (num= write(fifo, string, strlen(string)) &lt; 0) { 
       printf("\n %s \n", strerror(errno));
       return 0;
       }
  }
  </code></pre>