Pseudoterminal

A pseudo-terminal is a service in a Unix environment, which is usually provided by the kernel.

The pseudo-terminal is a type of interprocess communication, a two-way pipe that interprets the data flow and on configurable events specifically reacts. These additional functions of the pseudo terminals are the same, which are associated inside the kernel with a normal (e.g., serial ) terminal.

Pseudo terminals are used when a terminal-oriented application ( known examples are vim, top or less) should not be operated on a normal terminal, but, for example by means of an application such as telnet or ssh over a network. If one were to use the standard output of these processes directly, it would not make much sense, since a terminal always interprets the inputs, ie for certain special character performs certain actions.

Operation

A normal terminal allows text-oriented input / output. One side is always associated with a process, that is, the process has a device file of the terminal open ( / dev/ttyS0, / dev/tty1, ...). The other side of the terminal is, for example, connected with a serial interface (/ dev / ttySn ) or with a virtual machine console (monitor and keyboard) (/ dev / ttyn ) (n = 0, 1, 2, ...). When pseudo-terminal and the other side is not a device, ie a port of the computer, but connected to another process. A pseudo terminal has a master and a slave. The slave side is equivalent to a standard terminal device that is used by an application; the master page (in the kernel) directly connected to the slave side. The master is so, what is the serial port in a normal terminal, only that this happens with another process instead of using a device. Therefore, a pseudo-terminal is also a form of interprocess communication. In contrast to a pipe or a Unix domain socket, but the data is interpreted during transit from master to slave ( or vice versa). If certain escape sequences to be transmitted, they are not passed directly to the connected to the slave process, but solve a specific action. For example, the process that opened the slave side sent a SIGINT signal when it is written to the master 0x03 (Ctrl C). This interpretation is called flow control. If you press Ctrl S ( 0x13 ) is written to the master, then gets the process that has opened the slave (more precisely, has made the slave to its controlling tty ) a SIGSTOP signal and Ctrl Q ( 0x11 ) SIGCONT - signal.

These functions also has the device driver for a normal terminal, inter-process connection is added to these functions in a pseudo-terminal.

If it is, a process writes to the master, which is comparable to: a terminal device transmits data via the serial interface to the computer ( for example because the user typed something on the keyboard ). The additional function of pseudo-terminal to a pipe is so marginal, a shell is but important functions ( job control, flow control, character-based input ) can not provide you with a pipe. Frequently pseudo terminals for network- transparent terminal connections used (telnet, ssh) and for GUI-based terminal emulators ( xterm ).

Programs which use pseudo terminals

Implementations

There are two basic implementations of pseudo - terminals: The BSD implementation and the UNIX98 ( SUSv2 ) implementation. The BSD implementation should no longer be used in new programs.

After opening, both implementations behave exactly the same.

New Unix operating systems (current versions of Linux, FreeBSD ... ) provide mostly ready both implementations.

BSD

In the BSD implementation is available in the / dev already " prepared " pseudo terminals. The master terminals are according to the scheme / dev / ptypn (n = 1,2,3 ... ) named the slave terminals are named / dev / ttypn.

UNIX98 ( SUSv2 )

There is a master file, / dev / ptmx (pseudo terminal multiplexer ), which you can open any number of times. When opening a file descriptor for a master terminal is returned. Every time a new slave terminal is thereby allocated. The slaves are then called eg / dev/pts/1 / dev/pts/23 ...

  • Unix
664013
de