From: torvalds@klaava.Helsinki.FI (Linus Torvalds) Subject: Re: using FIFO's in Linux Date: 7 Aug 1993 12:37:55 +0300
In article <23uhoj$8a0@ionews.io.org> las@io.org (Laszlo Herczeg) writes:
> I want to have a text collector which reads from a named pipe into
>a file, appending new snippets of text to the end of the file.
>
>Here is what I did:
> mknod /dev/fifo p
>
>Then:
> "joe good-quotes </dev/fifo
>
>and on another VT I started sending text to the fifo with:
>cat >/dev/fifo
>
>Now, it does work, but only ONCE, so the process which has
>its stdin redirected to </dev/fifo exits with error level 0.
That's how a fifo is supposed to work as far as I can tell: when all
writers have exited, the reader gets an EOF and also exits..
>My wish is to keep the collector process going indefinitely, possibly in the
>background.
>Anyone care to comment?
You could try either:
while true; do cat /dev/fifo; done > quotes &
which restarts the cat every time, but it might be more clever to do
something like:
sleep 100000 > /dev/fifo &
cat /dev/fifo > quotes &
which puts a writer on the fifo that doesn't do anything, but which
makes sure the reader never exits due to the fifo not having any
writers. Then you can just write to the fifo every now and then and
collect all the writings into the "quotes" file.
Linus