how can I get filename from file descriptor?

Leslie Mikesell les at chinet.chi.il.us
Mon Oct 9 03:58:15 AEST 1989


In article <17109 at rpp386.cactus.org> jfh at rpp386.cactus.org (John F. Haugh II) writes:
>The only EOF UNIX has this lifetime is zero-length-read.
[....]
>Actually I think it's the best solution any has ever dreamt up.
>The only objects which I am aware of supporting multiple EOFs are
>tape devices [ and terminals, but more on that some other day ... ]

What about FIFOS, very handy objects available on SysV for the price
of typing "/etc/mknod filename p"?  If you happen to have machines
with RFS, the reader and writer need not even be on the same CPU (which
makes other forms of IPC difficult).  There are often good reasons for
wanting the process on the other end of the fd to think it received
an EOF (the same reasons you would type ^D at a terminal).  Normally,
with a FIFO, the reader receives EOF (i.e. read returns 0) when the
last process with the FIFO open for writing closes it.  However, this
scheme does not always work well, because a) multiple processes writing
to the same FIFO may not know about each other, b) the writing process
may not know the filename (the original topic of this thread) and may
wish to continue using the same channel, and c) it is often desirable to
open FIFO's for r/w to provice the correct blocking behaviour, in which
case the reader never sees a writer's close.

>The zero-length-read paradigm has a very intuitve meaning.  It
>means there is nothing left to read ...

No, it means there is nothing currently to read, even with files.  Otherwise
there would be no such thing as "tail -f".

Les Mikesell



More information about the Comp.unix.wizards mailing list