[ale] old school: pty and tty

John Wells jb at sourceillustrated.com
Fri Jan 31 15:42:46 EST 2003


Chris,

Thanks.  That gives me a start.  I'm working with some legacy code that
makes connections via both (tty and pty), and am looking for something
that descibes how to handle each.  I assume there are quite a few
differences.

Just saw a note on a google search that said the Stevens "Advanced
Programming in a Unix Environment" book is the place to look for this. 
I've got that on my shelf at home, so that's my next stop.

I appreciate the info.

John

cfowler said:
> I can give you a slight overview.  But really the only way you can
> experience the difference is to program for both.  Otherwise this is
> just incomprehensible stuff.
>
> tty:
>
> Real tty.  I guess you can call this a serial port, virtual terminal,
> etc.  These are devices that have some form of hardware attached to the
> other end.  In the ttyS0 it is usually a 16C550 UART. For tty[0-?]. It
> is a driver for video memory, keyboard and mouse.  On the serial side of
> things you can modify the UART registers.  You do that with an ioctl()
> command or the stty command which implements ioctl().  You can change
> parameters such as speed, char size, bits, signal status, etc...  You
> can modify the physical attributes of the hardware.
>
>
> pty:
>
> Pseudo tty.  This is not a reall tty.  It is really a pipe with some
> extra features.  It provides some of the POSIX services that a real tty
> provide.  Like the ability of becoming a controlling tty, different read
> modes.  Character attributes, etc.
>
> This device is really used when it comes to telnet, ssh, and other
> network programs that provide a tty to the user.  In the past a user
> wanted to communicate with a Unix box and login just as they are on a
> serial terminal.  But instead of over the network.  So UNIX programmers
> had to come up with a way to provide serial terminal like functions
> without the hardware.
>
> Slave Vs Master:
>
> In pseudo tty's you have a slave and a master.  When you log into a
> Linux box remotely and issue the tty command, the system will display
> the slave.  As far as you are concerned, your STDIN, STDOUT, and STDERR
> are all connected to the slave like /dev/ttyp0.  Signals and other
> things coming down the line behave as if you were on a serial port.
>
> CTRL-C.  When you  type your CTRL-C on you keyboard, the app does not
> see such a sequence.  The pty driver sees the CTRL-C then it signals
> SIGINT to the process that is control of that slave.  This is where
> controlling tty comes into play.
>
> The master:
>
> telnet really reads and writes to 2 file descriptors.  It will read from
> the master (ptyp0) and write to the socket.  It will read from the
> socker and write to the master (ptyp0).  The OS then passes that data
> through preprocessing for control chars, etc then it send the data to
> ttyp0 the slave.  That is how the relationship works.
>
> As you can see the only thing that makes a tty real is hardware on the
> other end. And what makes a pseudo-tty is software.
>
> I have a POSIX.1 Spec guide which goes into detail on the requirments.
> Or you can write some code.
>
>
> On Fri, 2003-01-31 at 15:16, John Wells wrote:
>> Anyone know any good links to explanations of the differences between
>> pty and tty, or a good overview of each?
>>
>> Thanks,
>> John
>>
>>
>> _______________________________________________
>> Ale mailing list
>> Ale at ale.org
>> http://www.ale.org/mailman/listinfo/ale
>
>
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://www.ale.org/mailman/listinfo/ale



_______________________________________________
Ale mailing list
Ale at ale.org
http://www.ale.org/mailman/listinfo/ale






More information about the Ale mailing list