[comp.unix.questions] tty

pearmana@prlhp1.prl.philips.co.uk (Andy Pearman) (02/01/90)

Could someone please remind me how the relation between

/dev/tty  and /dev/tty01  etc works

i.e.  If I do:

   echo "Hello" > /dev/tty

it comes out on /dev/tty01 etc

On doing an ls I see no obvious links and besides
everyones /dev/tty points somewhere different.

If you could shed some light on this matter I would be very
grateful.


  Andy


-- 

Andy Pearman, Computer Dept, Philips Research Labs, Redhill, Surrey, England. 
              pearmana@prl.philips.co.uk

jik@athena.mit.edu (Jonathan I. Kamens) (02/06/90)

In article <1044@prlhp1.prl.philips.co.uk>, pearmana@prlhp1.prl.philips.co.uk
(Andy Pearman) writes:
> Could someone please remind me how the relation between
> 
> /dev/tty  and /dev/tty01  etc works

  RTFM, that'll at least get you started.  At least in BSD, the
following paragraph appears in the man page tty(4):

     The file /dev/tty is, in each process, a synonym for a con-
     trol terminal associated with that process.  It is useful
     for programs that wish to be sure of writing messages on the
     terminal no matter how output has been redirected.  It can
     also be used for programs that demand a file name for out-
     put, when typed output is desired and it is tiresome to find
     out which terminal is currently in use.

The actual link between "/dev/tty" and whatever tty you happen to be
using is accomplished in the kernel -- when a process attempts to open
/dev/tty, the file descriptor returned by the kernel is a file
descriptor for the controlling terminal of the process.

  The name "/dev/tty" is not really what's significant; instead, the
major and minor device numbers of the file /dev/tty are what tell the
kernel that it should be treated as the tty file.  If you were to create
another device with the same
device numbers and a different name, the kernel would still give you an
fd for the controlling terminal if you were to open it.

Jonathan Kamens			              USnail:
MIT Project Athena				11 Ashford Terrace
jik@Athena.MIT.EDU				Allston, MA  02134
Office: 617-253-8495			      Home: 617-782-0710

donlash@uncle.UUCP (Donald Lashomb) (02/10/90)

In simple terms: /dev/tty is not connected to any single *real* tty, it
is a special program that connects to ->your<- terminal, whatever it may be.
Things like /dev/tty01..02..n are connected to *real* ttys.

-Don

jik@athena.mit.edu (Jonathan I. Kamens) (02/11/90)

In article <689@uncle.UUCP>, donlash@uncle.UUCP (Donald Lashomb) writes:
> In simple terms: /dev/tty is not connected to any single *real* tty, it
> is a special program that connects to ->your<- terminal, whatever it may be.
> Things like /dev/tty01..02..n are connected to *real* ttys.

Two points:

1. /dev/tty is not a "special program", it is a "special device".  A minor but
   significant difference.

2. Not all numbered tty's are connected to "*real* ttys"; I'm not even
sure what
   you mean by a "real" tty, so I'm assuming that by "real" you mean
"physical".
   However, pseudo-ttys (ptys) don't fall into that category, and yet a program
   running on a pty which opens /dev/tty *will* get something useful.

Jonathan Kamens			              USnail:
MIT Project Athena				11 Ashford Terrace
jik@Athena.MIT.EDU				Allston, MA  02134
Office: 617-253-8495			      Home: 617-782-0710