pty.7 (2010 09)

p
pty(7) pty(7)
NAME
pty - pseudo-terminal driver
DESCRIPTION
The
pty driver provides support for a device-pair termed a pseudo terminal. A pseudo terminal is a pair
of character devices, a master device and a slave device. The slave device provides to application
processes an interface identical to that described in termio (7). Unlike all other devices that provide the
interface described in termio (7), the slave device does not have a hardware device behind it. Instead, it
has another process manipulating it through the master half of the pseudo terminal. Thus anything writ-
ten on the master device is given to the slave device as input, and anything written on the slave device is
presented as input on the master device.
----------------
| pty functions |
Application <--> |----------------| <--> Server
Processes | Slave | Master | Process
| (pts) | (ptm) |
----------------
Open and Close Processing
The slave side of the
pty interprets opening or closing the master side as a modem connection or discon-
nection on a real terminal. Only one open to the master side of a pty is permitted. An attempt to open
an already open master side returns -1 and sets the external variable errno to [EBUSY]. An attempt to
open the master side of a pty that has a slave with an open file descriptor returns
-1 and sets errno to
[EBUSY]. The potential problem of
ptys being found busy at opens can be avoided by using the clone
open functionality discussed in the next section.
An attempt to open a nonexistent
pty returns -1 and sets errno to [ENXIO]. If O_NDELAY
is not
specified, opens on the slave side hang until the master side is opened. If
O_NDELAY
is specified, opens
on the slave side return error if the master side is closed. Any
ioctl() or write()
request made on
the slave side of a
pty after the master side is closed returns -1 and sets the external variable
errno to
[EIO]. A
read() request made on the slave side of a pty after the master side is closed returns 0 bytes.
Closing the master side of a pty sends a SIGHUP hangup signal to the tty process group number of the
corresponding slave side and flushes pending input and output.
Clone Open
In typical
pty usage, there is no preference among pty pairs. Thus, it is useful to be able to issue a sin-
gle open() that internally opens any available pty. An open on /dev/ptym/clone
returns an open
file descriptor of a free master
pty device. If there are no free devices, the open returns
-1 and sets
errno to [EBUSY]. The name of the slave device corresponding to the opened master device can be
found through a ptsname() request.
Processing ioctl() Requests
By default, any
ioctl() request defined by termio (7) is recognized by both the master and slave sides of
a pty. These ioctl() requests are processed by the pty driver as specified by termio (7). In addition,
the ioctl() requests defined below are recognized by the master side of a pty. The slave side only
recognizes ioctl() requests defined by termio (7). An ioctl() request made on the slave side of a
pty after the master side is closed returns -1 and sets the external variable errno to [EIO]. An
ioctl() request not recognized by the pty returns -1 and sets the external variable errno to [EIN-
VAL]. Note that some of the master-side-only ioctl() requests affect which ioctl() requests are
recognized by the master and slave side of the
pty. These master-side-only ioctl() requests also
affect the way recognized ioctl() requests, open() requests, and close() requests are processed by
the pty driver.
The following
ioctl() requests, defined in <sys/ptyio.h>, apply only to the master side of pty:
TIOCSIGSEND
Cause a signal to be sent from the slave side of the pty to the current tty process group
of the slave side. The value of the parameter is taken to be the signal number sent. An
[EINVAL] error is returned and no signal is sent if the specified signal number does not
refer to a legitimate signal (see signal (5)). Note that this request allows the server pro-
cess to send signals to processes not owned by the same user ID.
TIOCTTY Enable or disable all termio processing by a pty. termio processing is enabled if the
int addressed by arg is nonzero and disabled if the int addressed by arg is zero. By
HP-UX 11i Version 3: September 2010 1 Hewlett-Packard Company 1

Summary of content (8 pages)