The Linux Programming Interface

(nextflipdebug5) #1

PSEUDOTERMINALS


A pseudoterminal is a virtual device that provides an IPC channel. On one end of the
channel is a program that expects to be connected to a terminal device. On the
other end is a program that drives the terminal-oriented program by using the
channel to send it input and read its output.
This chapter describes the use of pseudoterminals, showing how they are
employed in applications such as terminal emulators, the script(1) program, and
programs such as ssh, which provide network login services.

64.1 Overview


Figure 64-1 illustrates one of the problems that pseudoterminals help us solve: how
can we enable a user on one host to operate a terminal-oriented program (e.g., vi)
on another host connected via a network?
As shown in the diagram, by permitting communication over a network, sockets
provide part of the machinery needed to solve this problem. However, we can’t
connect the standard input, output, and error of a terminal-oriented program directly
to a socket. This is because a terminal-oriented program expects to be connected to a
terminal—to be able to perform the terminal-oriented operations described in
Chapters 34 and 62. Such operations include placing the terminal in noncanonical
mode, turning echoing on and off, and setting the terminal foreground process
group. If a program tries to perform these operations on a socket, then the rele-
vant system calls will fail.
Free download pdf