Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

using FIFO's in Linux

13 views
Skip to first unread message

Laszlo Herczeg

unread,
Aug 6, 1993, 5:17:07 PM8/6/93
to
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.

Also the pair:
cat whatever >/dev/fifo
cat </dev/fifo >myfile
works fine.

My wish is to keep the collector process going indefinitely, possibly in the
background.
Anyone care to comment?

Laszlo

Linus Torvalds

unread,
Aug 7, 1993, 5:37:55 AM8/7/93
to
In article <23uhoj$8...@ionews.io.org> l...@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

Wm E. Davidsen Jr

unread,
Aug 8, 1993, 11:00:05 PM8/8/93
to
In article <23uhoj$8...@ionews.io.org> l...@io.org (Laszlo Herczeg) writes:

| Now, it does work, but only ONCE, so the process which has
| its stdin redirected to </dev/fifo exits with error level 0.
|
| Also the pair:
| cat whatever >/dev/fifo
| cat </dev/fifo >myfile
| works fine.
|
| My wish is to keep the collector process going indefinitely, possibly in the
| background.
| Anyone care to comment?

When the process writing the FIFO closes it the process reading the FIFO
get an EOF. That's the way it works in UNIX as far as I remember.

--
Bill Davidsen, davidsen%sixhu...@uunet.uu.net
TMR Associates, +1 518-370-5654
C programming, training, data gathering, porting to open systems,
heterogeneous environments, computer controlled housing, custom software

0 new messages