title: UNIX/Linux IPC : Reading from a pipe. How to know length of data at runtime?
body: <p>I have a child process which generates some output of variable length and then sends it to the parent using a half duplex pipe. In the parent, how do I use the read() function?
  Since the data can be of different length each time, how can I at run time know the size of the data to do any malloc() for a buffer? Can the fstat() function be used on a pipe file descriptor?</p>
  
  <p>I know that the read() function will read a specified number of bytes but will return 0 if the end of file (not the EOF character) is reached before the bytes requested have been read. </p>
  
  <p>I am specifically running Ubuntu GNU/Linux with a 2.6.27-9 Kernel. </p>
  
  <p>All examples in Richard Stevens' Advanced Programming in the UNIX Environment have specified either the length of data while writing into the pipe or have relied on fgets() stdio.h function. Since I am concerned with speed, I want to stay away from using stdio.h as much as possible. </p>
  
  <p>Will this be necessarily faster with shared memory?     </p>
  
  <p>Thanks,
  -Dhruv</p>