Pseudoterminal

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by Vadmium (talk | contribs) at 03:07, 5 November 2012 (→‎See also: Remove section; tty (Unix) now just redirects to Computer terminal). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Pseudo terminals as they are used by script(1)

In some operating systems, including Unix, a pseudo terminal is a pair of pseudo-devices, one of which, the slave, emulates a real text terminal device, the other of which, the master, provides the means by which a terminal emulator process controls the slave.

BSD PTYs

In the BSD PTY system, the slave device file, which generally has a nomenclature similar to /dev/tty[p-za-e][0-9a-f], supports the system calls of any text terminal device. Thus it supports login sessions. The master device file, which generally has a nomenclature similar to /dev/pty[p-za-e][0-9a-f], is the endpoint for communication with the terminal emulator.

With the aforementioned [p-za-e] naming scheme there can be at most 256 tty pairs. Also, finding the first free pty master can be racy unless a locking scheme is adopted. For that reason, modern BSD operating systems, such as FreeBSD, implement Unix98 PTYs.[1]

Unix98 PTYs

BSD PTYs have been rendered obsolete by Unix98 ptys whose nomenclature does not limit the number of pseudo-terminals and access to which occurs without danger of races.

/dev/ptmx is the "pseudo-terminal master multiplexer". Opening it returns a file descriptor of a master node and causes an associated slave node /dev/pts/N node to be created.[2]

Applications

The role of the terminal emulator process is to interact with the user; to feed text input to the master pseudo-device for use by the shell (which is connected to the slave pseudo-device) and to read text output from the master pseudo-device and show it to the user. The terminal emulator process must also handle terminal control commands, e.g., for resizing the screen. Widely used terminal emulator programs include xterm, GNOME Terminal and Mac OS X Terminal. Remote login handlers such as ssh and telnet servers play the same role but communicate with a remote user instead of a local one. Different again are programs such as expect.

Screen and Tmux are used to add a session context to a pseudo terminal, making for a much more robust and versatile solution. For example, it provides terminal persistence allowing to disconnect from one computer and connect later on from another computer on the net.

Origins

Pseudo terminals were present in the DEC PDP-6 Timesharing Monitor at least as early as 1967, and were used to implement batch processing.[3] They are described in the documentation for the succeeding TOPS-10 on the PDP-10.[4] Other DEC operating systems also had PTYs, including RSTS/E for the PDP-11, as did the third-party TENEX operating system for the PDP-10.

Unix pseudo terminals originated in 1983 during the development of Eighth Edition Unix and were based on a similar feature in TENEX.[5] They were part of the 4.2 release of BSD. AT&T's System V included support for pseudo terminals as a driver in their STREAMS device model, along with the pseudo terminal multiplexer.

References

  1. ^ "pty". man page. FreeBSD.
  2. ^ pts(4): pseudo-terminal master/slave - Linux man page
  3. ^ [1]
  4. ^ PDP-10 Timesharing Monitors Programmer's Reference Manual section 5.10
  5. ^ Ritchie, D. M. "A stream input-output system". AT&T Bell Laboratories Technical Journal. 63 (8): 1897–1910. CiteSeerx10.1.1.48.3730.