File system name space

Arnold Robbins arnold at mathcs.emory.edu
Wed Oct 31 02:12:19 AEST 1990


Submitted-by: arnold at mathcs.emory.edu (Arnold Robbins)

In article <14102 at cs.utexas.edu> addw at phcomp.co.uk (Alain Williams) writes:
>> I agree; it makes things like 
>> 
>> 	join <(prog1) <(prog2) > joined-output-of-progs-1-and-2
>> 
>> possible.
>Such things are possible *now*, you don't need /dev/fd to do it, just an
>intelligent shell that doesn't mind making & destroying fifos.

Yes, up to a point.  What happens though if you do

	nohup join <(prog1) <(prog2) > joined-output-of-progs-1-and-2 &

and then log out?  The temporary fifos will still be around when the
program finally exits and the shell won't be around to clean them up.
A cron job of some sort could maybe do it, but it's still not as clean
as /dev/fd.

>Anyway, the above wouldn't work with a straight /dev/fd as has been talked about
>here recently. Why ? The trouble is that if /dev/fd contains files with
>names "0", "1", ... "19", the programs prog1 & prog2 would both have a file
>/dev/fd/1 as their stdout, join would see another /dev/fd/1.

No.  The programs have their respective file descriptors 1 attached as pipes,
by the shell via dup, to other "files" in /dev/fd.  The join program would see

	join /dev/fd/4 /dev/fd/5

on its command line.  The scheme requires both /dev/fd and knowledge by the
shell to work completely.  Graphically, you have

	prog1[fd1]>------\
			  \
		     join[fd4][fd5][fd1]--> output
				/
	prog2[fd1]>-----------/

>What is really needed to do what is suggested above is for /proc to contain
>an fd directory, thus the command line above would be ``re written'' by the
>shell to something like:
>
>	join /proc/1234/fd/1 /proc/1235/fd/1 > joined-output-of-progs-1-and-2
>(where 1234 & 1235 are the process ids of prog1 and prog2).
>
>If we adopt the /proc/nnn/fd idea, more questions are raised, for instance what
>are the file permissions on /proc/nnn/fd ?

As explained above, this already happens.  Permissions on /dev/fd/* should be
666 since no process can affect any other's file descriptors.

>Let me remind the original purpose for which /dev/fd was proposed:
>provide a mechanism whereby programs could handle `-' to mean stdin/out
>as does cat, but without trying.

That's exactly what existing implementations do.  Having ported a version of
a /dev/fd driver into NFS based systems, and used KSH with process substitution
turned on, I can say from experience that it works just fine.  It is such
a nice thing to have that I make gawk (gnu awk) recognize file names of that
type internally and "do the right thing" even if the underlying system does
not support /dev/fd.
-- 
Arnold Robbins				AudioFAX, Inc. | Laundry increases
2000 Powers Ferry Road, #200 / Marietta, GA. 30067     | exponentially in the
INTERNET: arnold at audiofax.com Phone:   +1 404 933 7612 | number of children.
UUCP:	  emory!audfax!arnold Fax-box: +1 404 618 4581 |   -- Miriam Robbins

Volume-Number: Volume 22, Number 11



More information about the Comp.std.unix mailing list