Jump to content

devpts

From Wikipedia, the free encyclopedia
Simplified structure of theLinux kernel:Terminals and character device drivers, a.k.a. the "TTY subsystem".

devptsis a virtual filesystem directory available in theLinux kernelsince version 2.1.93 (April 1998). It is normally mounted at/dev/ptsand contains solely devices files which representslavesto the multiplexingmasterlocated at/dev/ptmxwhich in turn is used to implementterminal emulators(such as X11xterm).[1][2]

Terminal emulation

[edit]

Apseudoterminal( "pseudo TTY" or "PTY" ) is a pair ofpseudo-devices– aslaveand amaster– that provide a special sort of communication channel. The slave pseudo-device emulates a physical computer text terminal (like, e.g. theDEC VT100) it can read and write text as though it was such a physical terminal. Themasterpseudo-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 areterminal emulators(e.g.xterm,gnome-terminalorKonsole), or programs usingSSHortelnet.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 ofPOSIXdefined terminal devices (files) may operate infull-duplex mode.[4]Like pipes, pseudoterminals have a limited capacity. OnLinux,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 asetuidhelper 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/ptyp63and/dev/ttyp63,cf.The Linux Programming Interfacechapter 62 "Terminals" and chapter 64 "Pseudoterminals".

Implementation history

[edit]

In February 1998, Linux 2.1.87 brought support for the/dev/ptmxmultiplexing master device.[5]Opening this device provides access to an otherwise unused pseudo TTY master and allows the matching slave to be identified using anioctl().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 avoidcontext switchesat 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 knownEmacs.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

[edit]

References

[edit]
  1. ^Neil Brown (2016-06-01)."Containers, pseudo TTYs, and backward compatibility".LWN.net.
  2. ^"pts(4) - Linux manual page".man7.org.Retrieved2021-07-22.
  3. ^"Definitions".pubs.opengroup.org.Retrieved2021-07-22.
  4. ^"General Terminal Interface".pubs.opengroup.org.Retrieved2021-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.