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

  1. Submitted-by: arnold%audiofax.com@mathcs.emory.edu (Arnold Robbins)
  2.  
  3. In article <13878@cs.utexas.edu>, arnold@audiofax.com (that's me) writes
  4. lots of stuff about the wonders of /dev/fd, including this point:
  5.  
  6. >|>   Opening /dev/fd/7 is equivalent to doing a dup(7);
  7.  
  8. In article <14012@cs.utexas.edu> craig@b11.ingr.com (Craig Presson) writes:
  9. >But for those of us without access to every Unix manual ever published
  10. >(I do have a Version 7 Volume 1), could you fill in a bit more on the
  11. >semantics of this hybrid /dev entry? Like what do you get when you open
  12. >"/dev/fd/7" and there is no open file using that slot? Does the system
  13. >make these entries "invisible" to processes not using them? Do you just
  14. >get a classic "It's an error from Unix, you're not supposed to understand"
  15. >type return? Or am I Missing Something?
  16.  
  17. What happens when you do a dup(7) and 7 isn't a valid file descriptor?
  18. It returns -1 and errno is set to EBADF.   So, something along those lines
  19. happens if you open /dev/fd/7, and 7 isn't open.
  20.  
  21. Now, in article <14014@cs.utexas.edu> addw@phcomp.co.uk (Alain Williams) writes:
  22.  
  23. >What happens if you do an ``ls -l'' on /dev/fd, do you see the fds which are
  24. >open to the ls program or all possible fds, even those which aren't opened ?
  25.  
  26. Yes; the files in /dev/fd are character device files, with major and minor
  27. device numbers, just like the entries in /dev for all your ttys.  The major
  28. number is for the fd device driver routine, and the minor number indicates
  29. which fd you're trying to open.  It is a different animal than the /proc,
  30. which is mounted on an in-kernel filesystem.
  31.  
  32. >> (In fact, in V8 - V10, /dev/stdin, /dev/stdout, /dev/stderr, and /dev/tty are
  33. >> links to /dev/fd/0, /dev/fd/1, /dev/fd/2, and /dev/fd/3, respectively.  The
  34. >> last, in particular, is a nice generalization, and eliminates an ugly special
  35. >> case in the kernel; init just does one more dup.)
  36. >
  37. >I always thought that /dev/tty was a means of getting hold of the tty when
  38. >you couldn't be certain that 0,1,2 was connected to it. What you are really
  39. >saying is that the UNIX convention of 0,1,2 having ``pre defined uses'' be
  40. >extended to `3 always connected to the terminal and used for nothing else'.
  41. >It isn't a /dev/fd issue, it is a UNIX convention issue.
  42.  
  43. Exactly!  One of the major thrusts of recent versions of Research Unix has
  44. been to simplify, and become as minimalist as possible.  By having fd 3
  45. be the tty and /dev/tty a link to /dev/fd/3, the code in the kernel for
  46. doing /dev/tty goes away.
  47.  
  48. >The other thing is the /dev/tty is a guaranteed way of getting the terminal
  49. >& not something else (that is why the passwd program uses /dev/tty).
  50.  
  51. In general, unless someone went to the trouble, fd 3 will be attached to the
  52. terminal, so opening /dev/tty is pretty safe.  Nothing's foolproof; it's
  53. entirely possible that a process can get started off with no controlling
  54. terminal if its parent closed all open files and did the appropriate
  55. incantations to set the process group.  You're no worse off than before
  56. when /dev/tty was built into the kernel.
  57. -- 
  58. Arnold Robbins                AudioFAX, Inc. | Laundry increases
  59. 2000 Powers Ferry Road, #200 / Marietta, GA. 30067     | exponentially in the
  60. INTERNET: arnold@audiofax.com Phone:   +1 404 933 7612 | number of children.
  61. UUCP:      emory!audfax!arnold Fax-box: +1 404 618 4581 |   -- Miriam Robbins
  62.  
  63. Volume-Number: Volume 22, Number 8
  64.  
  65.