How do I know how much data is queued in a named pipe?

In a Linux box, I have several processes writing a named pipe, and another reading. I suspect my reader is not far behind and there is a lot of data in the pipe.

Can someone please tell me if there is a way to check / see how much data is queued in the pipe? Any Linux or C API team?

Thank you for your time.

- KS

+6
source share
2 answers

I don’t think that FIONREAD will work, since FIONREAD is determined by the value returned by i_size_read, which is stored in iode as i_size. i_size is not used with pipes (so stat always returns 0 for pipe size).

http://lxr.free-electrons.com/source/include/linux/fs.h#L848

It should be possible to get the size by adding the len property of the buffers (i_node.i_pipe.bufs). It doesn't look like this value is displayed by stat or ioctl, though.

https://github.com/mirrors/linux-2.6/blob/master/fs/pipe.c

+1
source

You can try recv (..., MSG_PEEK) - this should be read from the channel without deleting data from it (so the next reading will return the same data). This does not necessarily tell you about all the data in the queue, only some of them.

0
source

Source: https://habr.com/ru/post/899246/


All Articles