I can create a pipe to transfer information between two programs. I can even use a utility like pv to view progress of total data passing through the pipe. In my case I am using a named pipe. When data is written into the pipe, it will stay there until some other program reads it out.

Is it possible to print the current number of bytes in the pipe without actually reading them out?


Found these articles useful:



1 Answer 1


Note that when you do:

cmd > named-pipe

While there's no other process that has the pipe open for reading, it's the open() that hangs. That open() above is done by the shell, cmd is not even started, so won't have sent any data to it.

On a number of systems like Solaris, AIX or HP/UX, but not Linux, the number of bytes in the pipe if instantiated, would show in the size field of ls -l on the pipe.

On some systems (including Linux, see pipe(7) there), you can get the number of bytes in a pipe (named or not) with the FIONREAD ioctl(). However, that has to be run on a file descriptor on the pipe (to either end), which means that for a named pipe, you have to open it which means you may end-up instantiate the pipe as a side effect (and kill it upon close).

perl -le 'require "sys/ioctl.ph";
          ioctl(STDIN, &FIONREAD, $n) or die$!;
          print unpack "L", $n' <> named-pipe
  • Thanks to your reference of FIONREAD, I found more articles useful for the topic
    – dtmland
    Dec 14, 2016 at 18:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.