title: How to wait till data is written on the other end of pipe
body: <p>I am developing an application in C.
  Parent and child process communicate through pipe.
  Before writing to pipe, parent process execute another statements. In sample code, i have used sleep(10) to make delay.
  In the child process, it should read the data from the pipe.
  But data is not read on the read end of pipe in child process.</p>
  
  <pre><code>int main()
  {
      int pid;
      FILE *fp;
      fp = fopen("test.txt","w");
      char *buff;
      int fd[2];
      int count = 0 ;
      pipe(fd);
      pid = fork();
      if(pid == 0)
      {
          close(fd[1]);
          ioctl(fd[0], FIONREAD, &amp;count);
          fprintf(fp,"Value of count: %d ",count);
          buff = malloc(count);
          fprintf(fp,"\n TIME before read: %s",__TIME__);
          read(fd[0], buff, count);
          fprintf(fp,"\nbuffer: %s\n TIME after read %s", buff, __TIME__);
      }
      else{
          close(fd[0]);
          sleep(10);    //delay caused by application specific code replaced with sleep
          write(fd[1],"THIS is it",10);
      }
      fclose(fp);
      return 0;
  }
  </code></pre>
  
  <p>How to make child process wait till data is written on the other end?</p>