[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: dynamically generated files



* Tom Cook (tom.cook@adelaide.edu.au) [020429 00:53]:
> On  0, Vineet Kumar <debian-user@virtual.doorstop.net> wrote:
> > mkfifo /tmp/datefifo
> > 
> > while : 
> > do
> > echo `date` >> /tmp/datefifo
> > done
> > 
> > Then, see what happens when you cat /tmp/datefifo in another console.
> > (Try it a few times.)
> 
> I don't quite understand what this is doing.  What mechanism is used
> to implement the fifos?  And why does this happen?

These are traditional UNIX named pipes. It's a special type of "file"
into which process can write to and read from in a FIFO manner. 
Any writing blocks until another process reads.  Similarly, reading
blocks until another process writes.

This simple example has one process continually writing the date to the
fifo, and any other process can read the date from it. Something to note
is that reading the fifo as a file won't give you an endless file with a
continuous stream of dates from it; it will just give you one line
with the current date; as if you had used 'echo `date`' in place of
'cat /tmp/datefifo'.

> 
> # while true ; do echo `date` >> /tmp/datefifo ; done &
> # tail -f /tmp/datefifo
> Mon Apr 29 17:27:23 CST 2002
> Mon Apr 29 17:27:26 CST 2002
> Mon Apr 29 17:27:26 CST 2002
> Mon Apr 29 17:27:26 CST 2002
> Mon Apr 29 17:27:26 CST 2002
> 
> and that is all I get?  And why does the gnome-terminal with the while
> loop in it crash after a few more seconds?

I'm not sure. I'm running it in xterms like this:

while : ; do date > ~/tmp/datefifo ; done

and in a second xterm, any number of 

cat ~/tmp/datefifo

or even

while : ; do cat ~/tmp/datefifo ; done

don't affect the other process. My only guess is that using tail -f
is making it screwy somehow. Are you killing the tail with ^C ? Maybe
the other process gets a SIGPIPE and for some reason this takes the
gnome-terminal down with it. I've tried that in my setup as well, but
nothing I do seems to kill the original process. I also don't see why
you get multiple dates from a single 'tail' command.

It seems I don't fully understand this stuff either. =/ Maybe somebody
more knowledgeable can speak up and help us out.

Of course, this is also OT, so maybe somebody will yell at us and tell
us to go take it up in comp.os.unix.programming or some such.

good times,
Vineet

-- 
Currently seeking opportunities in the SF Bay Area
Please see http://www.doorstop.net/resume.shtml

Attachment: pgpl2DOZWQGBA.pgp
Description: PGP signature


Reply to: