Devpts
   HOME

TheInfoList



OR:

devpts is a virtual filesystem directory available in the
Linux kernel The Linux kernel is a Free and open-source software, free and open source Unix-like kernel (operating system), kernel that is used in many computer systems worldwide. The kernel was created by Linus Torvalds in 1991 and was soon adopted as the k ...
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 emulator 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 term ...
s (such as X11
xterm xterm is the standard terminal emulator for the X Window System. It allows users to run programs which require a command-line interface. If no particular program is specified, xterm runs the user's Unix shell, shell. An X display device, dis ...
).


Terminal emulation

A
pseudoterminal In some operating systems, including Unix-like systems, a pseudoterminal, pseudotty, or PTY is a pair of pseudo-device endpoints (files) which establish an asynchronous, bidirectional communication (IPC) channel (with two ports) between two or ...
("pseudo TTY" or "PTY") is a pair of
pseudo-device In Unix-like operating systems, a device file, device node, 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 specia ...
s – 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. Common use programs with a text-based user interface are
terminal emulator 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 term ...
s (e.g.
xterm xterm is the standard terminal emulator for the X Window System. It allows users to run programs which require a command-line interface. If no particular program is specified, xterm runs the user's Unix shell, shell. An X display device, dis ...
, gnome-terminal or Konsole), or programs using
SSH The Secure Shell Protocol (SSH Protocol) is a cryptographic network protocol for operating network services securely over an unsecured network. Its most notable applications are remote login and command-line execution. SSH was designed for Un ...
or
telnet Telnet (sometimes stylized TELNET) is a client-server application protocol that provides access to virtual terminals of remote systems on local area networks or the Internet. It is a protocol for bidirectional 8-bit communications. Its main ...
. 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. In terms of
POSIX The Portable Operating System Interface (POSIX; ) is a family of standards specified by the IEEE Computer Society for maintaining compatibility between operating systems. POSIX defines application programming interfaces (APIs), along with comm ...
defined terminal devices (files) may operate in full-duplex mode. Like pipes, pseudoterminals have a limited capacity. On
Linux Linux ( ) is a family of open source Unix-like operating systems based on the Linux kernel, an kernel (operating system), operating system kernel first released on September 17, 1991, by Linus Torvalds. Linux is typically package manager, pac ...
, 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 The Unix and Linux access rights flags setuid and setgid (short for ''set user identity'' and ''set group identity'') allow users to run an executable with the file system permissions of the executable's owner or group respectively and to chang ...
helper program, e.g. . 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 ''The Linux Programming Interface: A Linux and UNIX System Programming Handbook'' is a book written by Michael Kerrisk, which documents the Application programming interface, APIs of the Linux kernel and the GNU C Library (glibc). Book The boo ...
'' 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. Opening this device provides access to an otherwise unused pseudo TTY master and allows the matching slave to be identified using an . 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. The reason why the line discipline is inside the kernel, is to avoid
context switch In computing, a context switch is the process of storing the state of a process or thread, so that it can be restored and resume execution at a later point, and then restoring a different, previously saved, state. This allows multiple processes ...
es 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 Emacs (), originally named EMACS (an acronym for "Editor Macros"), is a family of text editors that are characterized by their extensibility. The manual for the most widely used variant, GNU Emacs, describes it as "the extensible, customizable, s ...
. 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.


See also

*
FIFO (computing and electronics) Representation of a FIFO queue In computing and in systems theory, first in, first out (the first in is the first out), acronymized as FIFO, is a method for organizing the manipulation of a data structure (often, specifically a data buffer) wh ...


References

{{Linux kernel Interfaces of the Linux kernel Pseudo file systems supported by the Linux kernel