Pseudoterminal

Last updated
Pseudoterminals as they are used by script unix command that records user's input for replaying it later. Termios-script-diagram.svg
Pseudoterminals as they are used by script unix command that records user's input for replaying it later.

In some operating systems, including Unix-like systems, a pseudoterminal, pseudotty, or PTY is a pair of pseudo-device endpoints (files) which establish asynchronous, bidirectional communication (IPC) channel (with two ports) between two or more processes. [1] [2] [3]

Contents

One pseudo-device in the pair, the master, provides means by which a terminal emulator or remote login server (e.g. a Telnet, rlogin, or Secure Shell server) [3] process controls the slave. The other pseudo-device, the slave, emulates a hardware serial port device, [1] and is used by terminal-oriented programs such as shells (e.g. bash) as a processes to read/write data back from/to master endpoint. [1] PTYs are similar to bidirectional pipes. [3] :1388

Devpts is a Linux kernel virtual file system containing pseudoterminal devices.

Linux implementation is based on System V-style terminals (commonly referred as UNIX 98 pseudoterminals) [4] and provides POSIX and the Single Unix Specification API in the form of a posix_openpt() function since 1998. [5]

History

Pseudoterminals were present in the DEC PDP-6 Timesharing Monitor at least as early as 1967, and were used to implement batch processing. They are described in the documentation for the succeeding TOPS-10 on the PDP-10. [6] 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.

Implementations of Unix pseudo terminals date back to the modifications that RAND and BBN made to a 6th Edition in the late 1970s to support remote access over a network. [7] Modern Unix pseudoterminals originated in 1983 during the development of Eighth Edition Unix and were based on a similar feature in TENEX. [8] They were part of the 4.2 release of BSD, with a rather cumbersome openpty() interface defined for use. [9]

AT&T's System V included support for pseudoterminals as a driver in their STREAMS device model, along with the pseudoterminal multiplexer (/dev/ptmx). This later evolved to become the Unix98 style of PTYs.

Books

The Linux Programming Interface from 2010 contains an entire chapter (chapter 64 "Pseudoterminals" p1375–1399.) explaining pseudoterminals. Then there is another one, Chapter 62 "Terminals", dedicated to terminals.

The Windows Console was extended to have a PTY interface called ConPTY in 2018. [10]

Applications

The role of the terminal emulator process is:

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, Konsole, and Terminal.

Remote login servers such as Secure Shell and Telnet servers play the same role but communicate with a remote user instead of a local one.

Also consider programs such as expect.

Screen and Tmux are used to add a session context to a pseudoterminal, making for a much more robust and versatile solution. For example, each provides terminal persistence, allowing a user to disconnect from one computer and then connect later from another computer.

Variants

In the BSD PTY system, the slave device file, which generally has a name of the form /dev/tty[p-za-e][0-9a-f], supports all system calls applicable to text terminal devices. Thus it supports login sessions. The master device file, which generally has a name of the form /dev/pty[p-za-e][0-9a-f], is the endpoint for communication with the terminal emulator. With this [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, recent BSD operating systems, such as FreeBSD, implement Unix98 PTYs. [11]

BSD PTYs have been rendered obsolete by Unix98 ptys whose naming system does not limit the number of pseudo-terminals and access to which occurs without danger of race conditions. /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 to be created. [12]

See also

Related Research Articles

<span class="mw-page-title-main">Cygwin</span> Unix subsystem for Windows machines

Cygwin is a Unix-like environment and command-line interface for Microsoft Windows.

<span class="mw-page-title-main">Plan 9 from Bell Labs</span> Distributed operating system

Plan 9 from Bell Labs is a distributed operating system which originated from the Computing Science Research Center (CSRC) at Bell Labs in the mid-1980s and built on UNIX concepts first developed there in the late 1960s. Since 2000, Plan 9 has been free and open-source. The final official release was in early 2015.

<span class="mw-page-title-main">Unix shell</span> Command-line interpreter for Unix operating system

A Unix shell is a command-line interpreter or shell that provides a command line user interface for Unix-like operating systems. The shell is both an interactive command language and a scripting language, and is used by the operating system to control the execution of the system using shell scripts.

<span class="mw-page-title-main">Terminal emulator</span> Program that emulates a video terminal

A terminal emulator, or terminal application, is a computer program that emulates a video terminal within some other display architecture. Though typically synonymous with a shell or text terminal, the term terminal covers all remote terminals, including graphical interfaces. A terminal emulator inside a graphical user interface is often called a terminal window.

The Open Sound System (OSS) is an interface for making and capturing sound in Unix and Unix-like operating systems. It is based on standard Unix devices system calls. The term also sometimes refers to the software in a Unix kernel that provides the OSS interface; it can be thought of as a device driver for sound controller hardware. The goal of OSS is to allow the writing of sound-based applications that are agnostic of the underlying sound hardware.

Filesystem in Userspace (FUSE) is a software interface for Unix and Unix-like computer operating systems that lets non-privileged users create their own file systems without editing kernel code. This is achieved by running file system code in user space while the FUSE module provides only a bridge to the actual kernel interfaces.

The proc filesystem (procfs) is a special filesystem in Unix-like operating systems that presents information about processes and other system information in a hierarchical file-like structure, providing a more convenient and standardized method for dynamically accessing process data held in the kernel than traditional tracing methods or direct access to kernel memory. Typically, it is mapped to a mount point named /proc at boot time. The proc file system acts as an interface to internal data structures about running processes in the kernel. In Linux, it can also be used to obtain information about the kernel and to change certain kernel parameters at runtime (sysctl).

In computer networking, STREAMS is the native framework in Unix System V for implementing character device drivers, network protocols, and inter-process communication. In this framework, a stream is a chain of coroutines that pass messages between a program and a device driver. STREAMS originated in Version 8 Research Unix, as Streams.

In computing, ioctl is a system call for device-specific input/output operations and other operations which cannot be expressed by regular file semantics. It takes a parameter specifying a request code; the effect of a call depends completely on the request code. Request codes are often device-specific. For instance, a CD-ROM device driver which can instruct a physical device to eject a disc would provide an ioctl request code to do so. Device-independent request codes are sometimes used to give userspace access to kernel functions which are only used by core system software or still under development.

In Unix-like operating systems, a loop device, vnd, or lofi is a pseudo-device that makes a computer file accessible as a block device.

<span class="mw-page-title-main">Virtual console</span> Computer user interface

A virtual console (VC) – also known as a virtual terminal (VT) – is a conceptual combination of the keyboard and display for a computer user interface. It is a feature of some Unix-like operating systems such as Linux, BSD, illumos, UnixWare, and macOS in which the system console of the computer can be used to switch between multiple virtual consoles to access unrelated user interfaces. Virtual consoles date back at least to Xenix and Concurrent CP/M in the 1980s.

getty, short for "get tty", is a Unix program running on a host computer that manages physical or virtual terminals (TTYs). When it detects a connection, it prompts for a username and runs the 'login' program to authenticate the user.

utmp, wtmp, btmp and variants such as utmpx, wtmpx and btmpx are files on Unix-like systems that keep track of all logins and logouts to the system.

In Unix-like operating systems, a device file or special file is an interface to a device driver that appears in a file system as if it were an ordinary file. There are also special files in DOS, OS/2, and Windows. These special files allow an application program to interact with a device by using its device driver via standard input/output system calls. Using standard system calls simplifies many programming tasks, and leads to consistent user-space I/O mechanisms regardless of device features and functions.

<span class="mw-page-title-main">Unix</span> Family of computer operating systems

Unix is a family of multitasking, multi-user computer operating systems that derive from the original AT&T Unix, whose development started in 1969 at the Bell Labs research center by Ken Thompson, Dennis Ritchie, and others.

The POSIX terminal interface is the generalized abstraction, comprising both an application programming interface for programs, and a set of behavioural expectations for users of a terminal, as defined by the POSIX standard and the Single Unix Specification. It is a historical development from the terminal interfaces of BSD version 4 and Seventh Edition Unix.

Entropy-supplying system calls are system calls in Unix-like operating system kernels through which processes can obtain entropic or random data. The first of these was getentropy, introduced to the OpenBSD operating system in release 5.6, as a refactoring of the sysctl(3) KERN_ARND approach used since 1997. Linux offers a very similar system call, getrandom, which was based on getentropy. It was first available in Linux 3.17, released in October 2014. In July 2015, Solaris introduced slightly modified versions of getentropy and getrandom. In August 2015, FreeBSD introduced the read_random system call for obtaining random data from the kernel.

devpts

devpts is a virtual filesystem directory available in the Linux kernel since version 2.1.93. It is normally mounted at /dev/pts and contains solely devices files which represent slaves to the multiplexing master located at /dev/ptmx which in turn is used to implement terminal emulators.

In computing, tty is a command in Unix and Unix-like operating systems to print the file name of the terminal connected to standard input.

In computing, a status key is a keyboard key that causes an operating system and/or a program to output status information on a terminal when it is pressed. In the event that a program on a terminal produces no indications that it is running, typing the status key will reveal the program's state and activity. Older implementations produced only a quick one-line status report for the current job when the status key was pressed. Newer implementations support sending a signal to the current process to allow the application to report on status as well.

References

  1. 1 2 3 "Pseudoterminal files". www.ibm.com. 2016-02-12. Retrieved 2021-09-30.
  2. "Chapter 64: Pseudoterminals - The Linux Programming Interface [Book]". www.oreilly.com. Retrieved 2021-09-30.
  3. 1 2 3 Kerrisk, Michael (2010). The Linux programming interface : a Linux and UNIX system programming handbook. San Francisco: No Starch Press. ISBN   978-1-59327-291-3. OCLC   728672600.
  4. "pty(7) - Linux manual page". man7.org. Retrieved 2021-09-30.
  5. posix_openpt   System Interfaces Reference, The Single UNIX Specification , Version 4 from The Open Group
  6. PDP-10 Timesharing Monitors Programmer's Reference Manual section 5.10
  7. ``PTY Driver for SRI-NOSC Net UNIX lines 15-31
  8. Ritchie, D. M. "A stream input-output system". AT&T Bell Laboratories Technical Journal. 63 (8): 1897–1910. CiteSeerX   10.1.1.48.3730 . doi:10.1002/j.1538-7305.1984.tb00071.x. S2CID   33497669.
  9. openpty(3)    FreeBSD Library Functions Manual
  10. "Introducing the Windows Pseudo Console (ConPTY)". Windows Command Line DevBolgs. 3 August 2018.
  11. pty(4)    FreeBSD Kernel Interfaces Manual
  12. pts(4)    Linux Programmer's Manual – Special Files