pty Special File


Provides the pseudo-terminal (pty) device driver.


The pty device driver provides support for a pseudo-terminal. A pseudo-terminal includes a pair of controller and worker character devices.
Note: Controller and worker devices are conventionally known as master and server devices. These terms are used interchangeably to use more inclusive language.
The worker device provides processes with essentially the same interface as that provided by the tty device driver. However, instead of providing support for a hardware device, the worker device is manipulated by another process through the control half of the pseudo-terminal. That is, anything written on the control device is given to the worker device as input and anything written on the worker device is presented as input on the control device.

In AIX® Version 4, the pty subsystem uses naming conventions similar to those from UNIX System V. There is one node for the control driver, /dev/ptc, and a maximum number of N nodes for the worker drivers, /dev/pts/n. N is configurable at pty configuration and may be changed dynamically by pty reconfiguration, without closing the opened devices.

The control device is set up as a clone device whose major device number is the clone device's major number and whose minor device number is the control driver's major number. There is no node in the filesystem for control devices. A control device can be opened only once, but worker devices can be opened several times.

By opening the control device with the /dev/ptc special file, an application can quickly open the control and worker sides of an unused pseudo-terminal. The name of the corresponding worker side can be retrieved using the ttyname subroutine, which always returns the name of the worker side.

With Berkeley pty subsystems, commands have to search for an unused pseudo-terminal by opening each control side sequentially. The control side could not be opened if it was already in use. Thus, the opens would fail, setting the errno variable to EIO, until an unused pseudo-terminal was found. It is possible to configure the pty subsystem in order to use special files with the BSD pty naming convention:

Item Description
Control devices /dev/pty[p-zA-Z][0-f]
worker devices /dev/tty[p-zA-Z][0-f]

These special files are not symbolic links to the operating system special files. They are completely separate. The number of control and worker pair devices using the BSD naming convention is configurable.

The following ioctl commands apply to pseudo-terminals:

Item Description
TIOCSTOP Stops output to a terminal. This is the same as using the Ctrl-S key sequence. No parameters are allowed for this command.
TIOCSTART Restarts output that was stopped by a TIOCSTOP command or by the Ctrl-S key sequence. This is the same as typing the Ctrl-Q key sequence. No parameters are allowed for this command.
TIOCPKT Enables and disables the packet mode. Packet mode is enabled by specifying (by reference) a nonzero parameter. It is disabled by specifying (by reference) a zero parameter. When applied to the control side of a pseudo-terminal, each subsequent read from the terminal returns data written on the worker part of the pseudo terminal. The data is preceded either by a zero byte (symbolically defined as TIOCPKT_DATA) or by a single byte that reflects control-status information. In the latter case, the byte is an inclusive OR of zero or more of the following bits:
The read queue for the terminal is flushed.
The write queue for the terminal is flushed.
Output to the terminal is stopped with Ctrl-S.
Output to the terminal is restarted.
The stop character defined by the current tty line discipline is Ctrl-S; the start character defined by the line discipline is Ctrl-Q.
The start and stop characters are not Ctrl-S and Ctrl-Q.

While this mode is in use, the presence of control-status information to be read from the control side can be detected by a select for exceptional conditions.

This mode is used by the rlogin and rlogind commands to log in to a remote host and implement remote echoing and local Ctrl-S and Ctrl-Q flow control with proper back-flushing of output.

TIOCUCNTL Enables and disables a mode that allows a small number of simple user ioctl commands to be passed through the pseudo-terminal, using a protocol similar to that of the TIOCPKT mode. The TIOCUCNTL and TIOCPKT modes are mutually exclusive.

This mode is enabled from the control side of a pseudo-terminal by specifying (by reference) a nonzero parameter. It is disabled by specifying (by reference) a zero parameter. Each subsequent read from the control side will return data written on the worker part of the pseudo-terminal, preceded either by a zero byte or by a single byte that reflects a user control operation on the worker side.

A user-control command consists of a special ioctl operation with no data. That command is issued as UIOCCMD(Value), where the Value parameter specifies a number in the range 1 through 255. The operation value is received as a single byte on the next read from the control side.

A value of 0 can be used with the UIOCCMD ioctl operation to probe for the existence of this facility. The zero is not made available for reading by the control side. Command operations can be detected with a select for exceptional conditions.

TIOCREMOTE A mode for the control half of a pseudo-terminal, independent of TIOCPKT. This mode implements flow control, rather than input editing, for input to the pseudo-terminal, regardless of the terminal mode. Each write to the control terminal produces a record boundary for the process reading the terminal. In normal usage, a write of data is like the data typed as a line on the terminal, while a write of zero bytes is like typing an end-of-file character. This mode is used for remote line editing in a window-manager and flow-controlled input.