home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / std_unix / volume.22 / text0010.txt < prev    next >
Encoding:
Text File  |  1991-03-06  |  2.9 KB  |  71 lines

  1. Submitted-by: arnold@mathcs.emory.edu (Arnold Robbins)
  2.  
  3. In article <14102@cs.utexas.edu> addw@phcomp.co.uk (Alain Williams) writes:
  4. >> I agree; it makes things like 
  5. >> 
  6. >>     join <(prog1) <(prog2) > joined-output-of-progs-1-and-2
  7. >> 
  8. >> possible.
  9. >Such things are possible *now*, you don't need /dev/fd to do it, just an
  10. >intelligent shell that doesn't mind making & destroying fifos.
  11.  
  12. Yes, up to a point.  What happens though if you do
  13.  
  14.     nohup join <(prog1) <(prog2) > joined-output-of-progs-1-and-2 &
  15.  
  16. and then log out?  The temporary fifos will still be around when the
  17. program finally exits and the shell won't be around to clean them up.
  18. A cron job of some sort could maybe do it, but it's still not as clean
  19. as /dev/fd.
  20.  
  21. >Anyway, the above wouldn't work with a straight /dev/fd as has been talked about
  22. >here recently. Why ? The trouble is that if /dev/fd contains files with
  23. >names "0", "1", ... "19", the programs prog1 & prog2 would both have a file
  24. >/dev/fd/1 as their stdout, join would see another /dev/fd/1.
  25.  
  26. No.  The programs have their respective file descriptors 1 attached as pipes,
  27. by the shell via dup, to other "files" in /dev/fd.  The join program would see
  28.  
  29.     join /dev/fd/4 /dev/fd/5
  30.  
  31. on its command line.  The scheme requires both /dev/fd and knowledge by the
  32. shell to work completely.  Graphically, you have
  33.  
  34.     prog1[fd1]>------\
  35.               \
  36.              join[fd4][fd5][fd1]--> output
  37.                 /
  38.     prog2[fd1]>-----------/
  39.  
  40. >What is really needed to do what is suggested above is for /proc to contain
  41. >an fd directory, thus the command line above would be ``re written'' by the
  42. >shell to something like:
  43. >
  44. >    join /proc/1234/fd/1 /proc/1235/fd/1 > joined-output-of-progs-1-and-2
  45. >(where 1234 & 1235 are the process ids of prog1 and prog2).
  46. >
  47. >If we adopt the /proc/nnn/fd idea, more questions are raised, for instance what
  48. >are the file permissions on /proc/nnn/fd ?
  49.  
  50. As explained above, this already happens.  Permissions on /dev/fd/* should be
  51. 666 since no process can affect any other's file descriptors.
  52.  
  53. >Let me remind the original purpose for which /dev/fd was proposed:
  54. >provide a mechanism whereby programs could handle `-' to mean stdin/out
  55. >as does cat, but without trying.
  56.  
  57. That's exactly what existing implementations do.  Having ported a version of
  58. a /dev/fd driver into NFS based systems, and used KSH with process substitution
  59. turned on, I can say from experience that it works just fine.  It is such
  60. a nice thing to have that I make gawk (gnu awk) recognize file names of that
  61. type internally and "do the right thing" even if the underlying system does
  62. not support /dev/fd.
  63. -- 
  64. Arnold Robbins                AudioFAX, Inc. | Laundry increases
  65. 2000 Powers Ferry Road, #200 / Marietta, GA. 30067     | exponentially in the
  66. INTERNET: arnold@audiofax.com Phone:   +1 404 933 7612 | number of children.
  67. UUCP:      emory!audfax!arnold Fax-box: +1 404 618 4581 |   -- Miriam Robbins
  68.  
  69. Volume-Number: Volume 22, Number 11
  70.  
  71.