Add Book to My BookshelfPurchase This Book Online

Appendix D - Pseudo-Terminals

UNIX Systems Programming for SVR4
David A. Curry
 Copyright © 1996 O'Reilly & Associates, Inc.

Appendix D: Pseudo-Terminals
Overview
There are times when it's useful to be able to execute a program on a terminal, but to have the input and output of the program connected to a program, rather than to the keyboard and screen. For example, some programs, such as passwd, insist on reading from the terminal—it is impossible to talk to programs like this via a pipe. Programs like rlogin and telnet need to set up a “terminal” on the remote host so that things like text editors will work, but their input and output must be connected, via the network, to the user's keyboard and screen. There are also times when it is convenient to be able to record all the input and output of a session; this is what the script utility does.
Most modern versions of UNIX provide a facility called pseudo-terminals that can be used for just these purposes. A pseudo-terminal is a software construct that acts like a terminal. A program running on a pseudo-terminal has no way of knowing whether it is attached to a real terminal or a pseudo-terminal (other than looking at the name of the device).
A pseudo-terminal is implemented as two devices, called the master and the slave. The master is opened by the controlling process (the one that wants to be the “keyboard” and ”screen”). The slave is opened by some process as its standard input and output; the process will see the slave as a terminal device. When the controlling process writes to the master device, the data will appear as input on the slave device, where the process there will see it as if it were typed on the keyboard. When the process running on the slave device writes to the “screen,” it will appear as input that the controlling process may read from the master device.

Previous SectionNext Section
Books24x7.com, Inc © 2000 –  Feedback