Chapter 16. Terminals and Pseudo Terminals

   


Devices designed for interactive use[1] all have a similar interface derived from the one created decades ago for serial TeleType paper-display terminals and thus dubbed the tty interface. The tty interface is used for accessing serial terminals, consoles, xterms, network logins, and more.

[1] That is, devices used both for input and for output.

This tty interface is simple in conception but complex in implementation. It is flexible and powerful, which makes it possible to write applications that do not know much about how they get their input and output and can run over the network, on a local screen, or through a modem. Applications can even run under the control of another program without being aware of it.

Unfortunately, it took the Unix implementors several tries to get the interface right. They have left us with three distinct interfaces for connecting to tty devices. The BSD sgtty and System V termio interfaces have now been superseded by the POSIX termios interface, which is a superset of the termio interface. Because all current systems support the termios interface, and because it is the most powerful of the interfaces, we document only termios, not the earlier interfaces. (For the sake of supporting legacy source code, Linux supports termio, as well as termios. It also used to support the sgtty interface in a limited way, but that support has been removed because it was never perfect, and because there was no longer significant demand for it.)

Not only does the termios interface have to support interactive program use, but it must also support other kinds of data traffic. The same serial line over which you log in using a modem you might also use for dialing out via a modem, to talk to a serial printer, or to talk to some specialized piece of hardware.

A tty device has two ends. The simplistic view is that one end is attached to the program and the other end is attached to the hardware device. This is true for a serial port; in this case, the serial device driver attaches the serial port (and thereby the terminal or modem) to a shell, editor, or other program. It is also true for the console; the console driver connects the keyboard and screen to the same types of programs. But in some cases, there is a program on each end; in these cases, one of the ends takes the place of hardware. For instance, with a network connection, one end of the tty device is connected to a program that provides the network connection, and the other end is connected to the shell, editor, or other potentially interactive program. When there is a program at each end, you need to keep a clear idea of which end is emulating hardware; in the case of network connections, the side that connects to the network is the hardware side.

tty devices that have software at both ends are called pseudo ttys, or, simply, ptys. For the first part of this chapter, you can pretend that they do not exist, because the "software" end of a pty is handled just like any tty device. Later on, we talk about programming the "hardware" end of a pty.


       
    top
     


    Linux Application Development
    Linux Application Development (paperback) (2nd Edition)
    ISBN: 0321563220
    EAN: 2147483647
    Year: 2003
    Pages: 168

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net