Get using pipes?

This is marked as an answer, but if anyone knows a system call similar to fstat that can do this, I'd love to hear about it.

I am working on some applications that communicate over a named pipe (required for legacy reasons). The pipe has a fixed capacity (65536 bytes - Linux default), and when it fills up, it blocks until enough space is available. This means that the slower consumer blocks the faster producer. What I would like to do is track pipe usage periodically.

Is it possible to get the size of the pipe data (the size of the data not yet read from the pipe)? fstat always returns 0 for size, expected behavior according to the man page.

Is there a posix compatible way to get bandwidth? Apparently fcntl can do this with Linux 2.6.35. However, this is required to run on an earlier Linux version.

+3


source to share


1 answer


Open the pipe in non-blocking mode at one or both ends and always try to read or write the full capacity of the buffer. read

/ write

will likely return less than this.



Which returns non-blocking read

how much was in the tube at the time. Which non-blocking returns write

how much space is left in the pipe.

+1


source







All Articles