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