Chapter 10. Terminal Handling

   


Historically, users interacted with the system using terminals connected to the computer through hardwired RS-232 serial lines. Although most computers still have one or two hardwired serial lines, their use is mostly relegated to running the system console, slow speed modems, serially connected printers, and similar devices. Although hardwired terminals are largely a footnote in history, the character processing done for keyboard I/O is still important.

The most common type of user session in FreeBSD uses a pseudo-terminal, or pty. The pseudo-terminal driver provides support for a device pair, termed the master and slave devices. The slave device provides to a process an interface identical to the one described for terminals in this chapter. However, instead of being associated with a hardware device to read and write characters, the slave device has another process manipulating it through the master half of the pseudo-terminal. That is, anything written on the master device is provided to the slave device as input, and anything written on the slave device is presented to the master device as input. The driver for the master device emulates all specific hardware support details described in the rest of this chapter.

Pseudo-terminals are used by the terminal emulator, xterm, as well as the common remote-login programs such as ssh and telnet. In a typical use, xterm opens the master side of a pseudo-terminal and directs the keystrokes from the window manager to its input while taking its output and drawing the characters in its window. It forks a process that opens the slave side of the pseudo-terminal and then runs the user's preferred shell with the slave set up as the standard input, output, and error. As each keystroke is typed by the user, it is written into the master side of the pseudo-terminal, where it is processed by the line discipline and eventually emerges as input to the user's shell. Output from the shell is written into the slave side of the pseudo-terminal, where it is processed by the line discipline and eventually emerges from the master side and is displayed in the xterm window.

Like the terminal devices that preceded them, the pseudo-terminal driver commonly processes data one character at a time using the character-device interface described in Section 6.2. As each character is typed at the keyboard or arrives from a user over the network, it is presented as input to the master side of the pseudo-terminal. The input of characters is independent of process requests to read user input from the slave side of the pseudo-terminal. Characters are processed when they are received and then are stored until a process requests them, thus allowing type-ahead. When a pseudo-terminal supports a user interaction with the system, terminal input represents the keystrokes of the user, and terminal output is displayed on the user's screen. We deal mostly with this type of pseudo-terminal usage in this chapter. When we use the term terminal, we are describing a concept that applies to both pseudo-terminals and hardwired terminal devices.

Asynchronous serial lines also connect modems for computer-to-computer communications or serial-interface printers. When serial interfaces are used for these purposes, they generally use a subset of the system's terminal-handling capability. Sometimes, they use special processing modules for higher efficiency. We discuss alternate terminal modules in Section 10.9.


   
 


The Design and Implementation of the FreeBSD Operating System
The Design and Implementation of the FreeBSD Operating System
ISBN: 0201702452
EAN: 2147483647
Year: 2003
Pages: 183

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