[LCP]stat'ing a FIFO

Steve Baker ice at mama.indstate.edu
Thu Jul 26 04:32:04 UTC 2001


Robert Wuest <rwuest at wuest.org> wrote:
> Can anyone tell me how to stat a FIFO?  In a program 1, I pipe() twice,
> then fork. In the child, I dup() the appropiate fd's to stdin and
> stdout, and exec program 2.  Normal stuff.  In either program: 	
>
> 	struct stat stat_buf; 
> 	fstat( fd, &stat_buf );  // fd = 0 or 1 in program 2's case
>
> always has 0 for the size, stat_buf.st_size.  Even when I know there is
> unread data in there.  Read or write. Is there some other trick I need
> to know?

  I believe what you're looking for is the FIONREAD ioctl(), thus:

  int n;
...
  ioctl(fd,FIONREAD,&n);

  /*
   * n now contains the number of bytes available for reading on the
   * descriptor fd.
   */

> Also, is there anyway to get a signal when there is data to be read?

  SIGIO is supposed to be for that, but I've never used it, and don't know if
it even works.  I think it might be limited to tty I/O events.

								- Steve



More information about the linuxCprogramming mailing list