Devpts

Last updated
Simplified structure of the Linux kernel: Terminals and character device drivers, a.k.a. the "TTY subsystem". Simplified Structure of the Linux Kernel.svg
Simplified structure of the Linux kernel: Terminals and character device drivers, a.k.a. the "TTY subsystem".

devpts is a virtual filesystem directory available in the Linux kernel since version 2.1.93 (April 1998). 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 (such as X11 xterm). [1] [2]

Contents

Terminal emulation

A pseudoterminal ("pseudo TTY" or "PTY") is a pair of pseudo-devices – a slave and a master – that provide a special sort of communication channel. The slave pseudo-device emulates a physical computer text terminal (like, e.g. the DEC VT100) it can read and write text as though it was such a physical terminal. The master pseudo-device provides the means by which a program providing a text-based user interface acts with and controls its slave.

Widely spread programs with a text-based user interface are terminal emulators (e.g. xterm, gnome-terminal or Konsole), or programs using SSH or telnet. Writing to the master is exactly like typing on a terminal, thus the master pseudo-device acts kind of like the person sitting in front of the physical computer text terminal.

A pseudoterminal pair is similar to a bidirectional pipe. Anything that is written on the master appears as input on the slave, and anything that is written on the slave appears as input on the master. [3] In terms of POSIX defined terminal devices (files) may operate in full-duplex mode. [4] Like pipes, pseudoterminals have a limited capacity. On Linux, the pseudoterminal capacity is about 4 KiB in each direction.

A typical Linux kernel-based operating system provides many PTYs to support text-based interfaces as provided by terminal emulators (such as xterm or gnome-terminal) and remote access interfaces like SSH.

The creation of devpts resulted from the wish to abandon the need for a setuid helper program, e.g. /usr/libexec/pt_chown. It is a distinct implementation of the pseudoterminal idea; the previous implementation provided a fixed number of master/slave pairs which had permanent device nodes, for example the master-slave pair /dev/ptyp63 and /dev/ttyp63, cf. The Linux Programming Interface chapter 62 "Terminals" and chapter 64 "Pseudoterminals".

Implementation history

In February 1998, Linux 2.1.87 brought support for the /dev/ptmx multiplexing master device. [5] Opening this device provides access to an otherwise unused pseudo TTY master and allows the matching slave to be identified using an ioctl(). In April of that year, Linux 2.1.93 added a new virtual filesystem called devpts that is normally mounted at /dev/pts. Whenever a new master/slave pair is created, a device node for the slave is created in that virtual filesystem.

To facilitate moving the terminal emulation into userland, while still keeping the TTY subsystem (session management and line discipline) intact, the pseudoterminal was invented. [6]

The reason why the line discipline is inside the kernel, is to avoid context switches at the reception of each character (which in the early times of small core memories, would imply swap-outs and swap-ins!). So the line discipline keeps in a kernel buffer a line of input, and since it is simple enough to test for a specific byte and decrement a counter to implement the backspace "editing" (and a few other simple editing functions), it's done there.

The alternative is to use the raw mode, where the characters are forwarded to the application as soon as they're received, which is needed for more sophisticated editors, like the (at the time) famously known Emacs. And indeed, since emacs had to use this raw mode, which implies a context switch at the reception of each character typed, it was constantly swapping when the computers hadn't enough memory to keep emacs and all the other programs in core.

With the addition of pseudo terminals (PTYs), the TTY code has also become a sort of interprocess communication mechanism, with all of the TTY semantics preserved. The TTY code also needs to support networking protocols like PPP without creating performance bottlenecks. [7]

See also

Related Research Articles

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

Cygwin is a POSIX-compatible programming and runtime environment that runs natively on Microsoft Windows. Under Cygwin, source code designed for Unix-like operating systems may be compiled with minimal modification and executed.

<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.

<span class="mw-page-title-main">ANSI escape code</span> Method used for display options on video text terminals

ANSI escape sequences are a standard for in-band signaling to control cursor location, color, font styling, and other options on video text terminals and terminal emulators. Certain sequences of bytes, most starting with an ASCII escape character and a bracket character, are embedded into text. The terminal interprets these sequences as commands, rather than text to display verbatim.

<span class="mw-page-title-main">Text-based user interface</span> Type of interface based on outputting to or controlling a text display

In computing, text-based user interfaces (TUI), is a retronym describing a type of user interface (UI) common as an early form of human–computer interaction, before the advent of graphical user interfaces (GUIs). Like GUIs, they may use the entire screen area and accept mouse and other inputs. They may also use color and often structure the display using special graphical characters such as ┌ and ╣, referred to in Unicode as the "box drawing" set. The modern context of use is usually a terminal emulator.

<span class="mw-page-title-main">Konsole</span> Terminal emulator

Konsole is a free and open-source terminal emulator graphical application which is part of KDE Applications and ships with the KDE desktop environment. Konsole was originally written by Lars Doelle.He is also a song producer from coventry in the UK. It ls licensed under the GPL-2.0-or-later and the GNU Free Documentation License.

A chroot on Unix and Unix-like operating systems is an operation that changes the apparent root directory for the current running process and its children. A program that is run in such a modified environment cannot name files outside the designated directory tree. The term "chroot" may refer to the chroot(2) system call or the chroot(8) wrapper program. The modified environment is called a chroot jail.

<span class="mw-page-title-main">Pseudoterminal</span>

In some operating systems, including Unix and Linux, a pseudoterminal, pseudotty, or PTY is a pair of pseudo-device endpoints (files) which establish asynchronous, bidirectional communication (IPC) channel between two or more processes. The master provides means by which a terminal emulator process controls the slave. The slave, emulates a hardware text terminal device. PTY are similar to bidirectional pipes.

fstab is a system file commonly found in the directory /etc on Unix and Unix-like computer systems. In Linux, it is part of the util-linux package. The fstab file typically lists all available disk partitions and other types of file systems and data sources that may not necessarily be disk-based, and indicates how they are to be initialized or otherwise integrated into the larger file system structure.

Linux Terminal Server Project (LTSP) is a free and open source terminal server for Linux that allows many people to simultaneously use the same computer. Applications run on the server with a terminal known as a thin client handling input and output. Generally, terminals are low-powered, lack a hard disk and are quieter and more reliable than desktop computers because they do not have any moving parts.

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).

sysfs is a pseudo file system provided by the Linux kernel that exports information about various kernel subsystems, hardware devices, and associated device drivers from the kernel's device model to user space through virtual files. In addition to providing information about various devices and kernel subsystems, exported virtual files are also used for their configuration.

<span class="mw-page-title-main">GNOME Terminal</span> Terminal emulator from GNOME

GNOME Terminal is a terminal emulator for the GNOME desktop environment written by Havoc Pennington and others. Terminal emulators allow users to access a UNIX shell while remaining on their graphical desktop.

inotify is a Linux kernel subsystem created by John McCutchan, which monitors changes to the filesystem, and reports those changes to applications. It can be used to automatically update directory views, reload configuration files, log changes, backup, synchronize, and upload. The inotifywait and inotifywatch commands allow using the inotify subsystem from the command line. One major use is in desktop search utilities like Beagle, where its functionality permits reindexing of changed files without scanning the filesystem for changes every few minutes, which would be very inefficient.

In computing, ioctl is a system call for device-specific input/output operations and other operations which cannot be expressed by regular system calls. 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 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">ZOC (software)</span>

ZOC is a popular computer-based terminal emulator and Telnet software client for the Microsoft Windows and Apple Macintosh macOS operating systems that supports telnet, modem, SSH 1 and 2, ISDN, serial, TAPI, Rlogin and other means of communication. Its terminal emulator supports Xterm emulation with full colors, meta-keys and local printing, VT102, VT220 and several types of ANSI as well as Wyse, TVI, TN3270, and Sun's CDE. It supports full keyboard remapping, scripting in REXX and other languages, and support for named pipes.

<span class="mw-page-title-main">Linux console</span> Console of the Linux kernel

The Linux console is a system console internal to the Linux kernel. A system console is the device which receives all kernel messages and warnings and which allows logins in single user mode. The Linux console provides a way for the kernel and other processes to send text output to the user, and to receive text input from the user. The user typically enters text with a computer keyboard and reads the output text on a computer monitor. The Linux kernel supports virtual consoles – consoles that are logically separate, but which access the same physical keyboard and display. The Linux console are implemented by the VT subsystem of the Linux kernel, and do not rely on any user space software. This is in contrast to a terminal emulator, which is a user space process that emulates a terminal, and is typically used in a graphical display environment.

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.

luit

luit is a utility program used to translate the character set of a computer program so that its output can be displayed correctly on a terminal emulator that uses a different character set. Whereas iconv converts the character set of strings or text files at rest, luit converts the input and output of programs running interactively.

References

  1. Neil Brown (2016-06-01). "Containers, pseudo TTYs, and backward compatibility". LWN.net.
  2. "pts(4) - Linux manual page". man7.org. Retrieved 2021-07-22.
  3. "Definitions". pubs.opengroup.org. Retrieved 2021-07-22.
  4. "General Terminal Interface". pubs.opengroup.org. Retrieved 2021-07-22.
  5. "diff of /drivers/char/pty.c".
  6. Linus Akesson. "The TTY demystified".
  7. Jonathan Corbet (2009-07-29). "A tempest in a tty pot". LWN.net.