1PTY(7) Linux Programmer's Manual PTY(7)
2
3
4
6 pty - pseudoterminal interfaces
7
9 A pseudoterminal (sometimes abbreviated "pty") is a pair of virtual
10 character devices that provide a bidirectional communication channel.
11 One end of the channel is called the master; the other end is called
12 the slave.
13
14 The slave end of the pseudoterminal provides an interface that behaves
15 exactly like a classical terminal. A process that expects to be con‐
16 nected to a terminal, can open the slave end of a pseudoterminal and
17 then be driven by a program that has opened the master end. Anything
18 that is written on the master end is provided to the process on the
19 slave end as though it was input typed on a terminal. For example,
20 writing the interrupt character (usually control-C) to the master de‐
21 vice would cause an interrupt signal (SIGINT) to be generated for the
22 foreground process group that is connected to the slave. Conversely,
23 anything that is written to the slave end of the pseudoterminal can be
24 read by the process that is connected to the master end.
25
26 Data flow between master and slave is handled asynchronously, much like
27 data flow with a physical terminal. Data written to the slave will be
28 available at the master promptly, but may not be available immediately.
29 Similarly, there may be a small processing delay between a write to the
30 master, and the effect being visible at the slave.
31
32 Historically, two pseudoterminal APIs have evolved: BSD and System V.
33 SUSv1 standardized a pseudoterminal API based on the System V API, and
34 this API should be employed in all new programs that use pseudotermi‐
35 nals.
36
37 Linux provides both BSD-style and (standardized) System V-style pseu‐
38 doterminals. System V-style terminals are commonly called UNIX 98
39 pseudoterminals on Linux systems.
40
41 Since kernel 2.6.4, BSD-style pseudoterminals are considered depre‐
42 cated: support can be disabled when building the kernel by disabling
43 the CONFIG_LEGACY_PTYS option. (Starting with Linux 2.6.30, that op‐
44 tion is disabled by default in the mainline kernel.) UNIX 98 pseu‐
45 doterminals should be used in new applications.
46
47 UNIX 98 pseudoterminals
48 An unused UNIX 98 pseudoterminal master is opened by calling
49 posix_openpt(3). (This function opens the master clone device,
50 /dev/ptmx; see pts(4).) After performing any program-specific initial‐
51 izations, changing the ownership and permissions of the slave device
52 using grantpt(3), and unlocking the slave using unlockpt(3)), the cor‐
53 responding slave device can be opened by passing the name returned by
54 ptsname(3) in a call to open(2).
55
56 The Linux kernel imposes a limit on the number of available UNIX 98
57 pseudoterminals. In kernels up to and including 2.6.3, this limit is
58 configured at kernel compilation time (CONFIG_UNIX98_PTYS), and the
59 permitted number of pseudoterminals can be up to 2048, with a default
60 setting of 256. Since kernel 2.6.4, the limit is dynamically ad‐
61 justable via /proc/sys/kernel/pty/max, and a corresponding file,
62 /proc/sys/kernel/pty/nr, indicates how many pseudoterminals are cur‐
63 rently in use. For further details on these two files, see proc(5).
64
65 BSD pseudoterminals
66 BSD-style pseudoterminals are provided as precreated pairs, with names
67 of the form /dev/ptyXY (master) and /dev/ttyXY (slave), where X is a
68 letter from the 16-character set [p-za-e], and Y is a letter from the
69 16-character set [0-9a-f]. (The precise range of letters in these two
70 sets varies across UNIX implementations.) For example, /dev/ptyp1 and
71 /dev/ttyp1 constitute a BSD pseudoterminal pair. A process finds an
72 unused pseudoterminal pair by trying to open(2) each pseudoterminal
73 master until an open succeeds. The corresponding pseudoterminal slave
74 (substitute "tty" for "pty" in the name of the master) can then be
75 opened.
76
78 /dev/ptmx
79 UNIX 98 master clone device
80
81 /dev/pts/*
82 UNIX 98 slave devices
83
84 /dev/pty[p-za-e][0-9a-f]
85 BSD master devices
86
87 /dev/tty[p-za-e][0-9a-f]
88 BSD slave devices
89
91 Pseudoterminals are used by applications such as network login services
92 (ssh(1), rlogin(1), telnet(1)), terminal emulators such as xterm(1),
93 script(1), screen(1), tmux(1), unbuffer(1), and expect(1).
94
95 A description of the TIOCPKT ioctl(2), which controls packet mode oper‐
96 ation, can be found in ioctl_tty(2).
97
98 The BSD ioctl(2) operations TIOCSTOP, TIOCSTART, TIOCUCNTL, and TIOCRE‐
99 MOTE have not been implemented under Linux.
100
102 ioctl_tty(2), select(2), setsid(2), forkpty(3), openpty(3), termios(3),
103 pts(4), tty(4)
104
106 This page is part of release 5.13 of the Linux man-pages project. A
107 description of the project, information about reporting bugs, and the
108 latest version of this page, can be found at
109 https://www.kernel.org/doc/man-pages/.
110
111
112
113Linux 2020-08-13 PTY(7)