Named pipe behavior: Flushing pipes

Joel Hammer joel
Mon May 17 11:56:45 PDT 2004


Using named pipes in bash:
A book says that:
echo My message > pipe
will block if there is no program reading the pipe. On my system, the
command doesn't block. You can use echo over and over to send things to
the pipe.
eg:
	echo line 1 > pipe
	echo line 2 > pipe

If you then type this:
cat < pipe
This blocks, even though the pipe is full of stuff.

If you echo one more thing to the pipe (in another terminal, leaving
that blocked cat statement alone), like:

	echo last line

everything in the pipe is printed out

line 1
line 2
last line

with that blocking cat command suddenly waking up.

SO:
How can you make the cat command read the contents of the pipe
without having to have an additional echo command to flush the pipe?


Joel



More information about the Linux-users mailing list