1 .\" Copyright (C) 2005 Michael Kerrisk <mtk.manpages@gmail.com>
3 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
5 .TH pty 7 (date) "Linux man-pages (unreleased)"
7 pty \- pseudoterminal interfaces
9 A pseudoterminal (sometimes abbreviated "pty")
10 is a pair of virtual character devices that
11 provide a bidirectional communication channel.
12 One end of the channel is called the
14 the other end is called the
17 The slave end of the pseudoterminal provides an interface
18 that behaves exactly like a classical terminal.
19 A process that expects to be connected to a terminal,
20 can open the slave end of a pseudoterminal and
21 then be driven by a program that has opened the master end.
22 Anything that is written on the master end is provided to the process
23 on the slave end as though it was input typed on a terminal.
24 For example, writing the interrupt character (usually control-C)
25 to the master device would cause an interrupt signal
27 to be generated for the foreground process group
28 that is connected to the slave.
29 Conversely, anything that is written to the slave end of the
30 pseudoterminal can be read by the process that is connected to
33 Data flow between master and slave is handled asynchronously,
34 much like data flow with a physical terminal.
35 Data written to the slave will be available at the master promptly,
36 but may not be available immediately.
37 Similarly, there may be a small processing delay between
38 a write to the master, and the effect being visible at the slave.
40 Historically, two pseudoterminal APIs have evolved: BSD and System V.
41 SUSv1 standardized a pseudoterminal API based on the System V API,
42 and this API should be employed in all new programs that use
45 Linux provides both BSD-style and (standardized) System V-style
47 System V-style terminals are commonly called UNIX 98 pseudoterminals
50 Since Linux 2.6.4, BSD-style pseudoterminals are considered deprecated:
51 support can be disabled when building the kernel by disabling the
54 (Starting with Linux 2.6.30,
55 that option is disabled by default in the mainline kernel.)
56 UNIX 98 pseudoterminals should be used in new applications.
57 .SS UNIX 98 pseudoterminals
58 An unused UNIX 98 pseudoterminal master is opened by calling
60 (This function opens the master clone device,
64 After performing any program-specific initializations,
65 changing the ownership and permissions of the slave device using
67 and unlocking the slave using
69 the corresponding slave device can be opened by passing
75 The Linux kernel imposes a limit on the number of available
76 UNIX 98 pseudoterminals.
77 Up to and including Linux 2.6.3, this limit is configured
78 at kernel compilation time
79 .RB ( CONFIG_UNIX98_PTYS ),
80 and the permitted number of pseudoterminals can be up to 2048,
81 with a default setting of 256.
82 Since Linux 2.6.4, the limit is dynamically adjustable via
83 .IR /proc/sys/kernel/pty/max ,
84 and a corresponding file,
85 .IR /proc/sys/kernel/pty/nr ,
86 indicates how many pseudoterminals are currently in use.
87 For further details on these two files, see
89 .SS BSD pseudoterminals
90 BSD-style pseudoterminals are provided as precreated pairs, with
96 where X is a letter from the 16-character set [p\-za\-e],
97 and Y is a letter from the 16-character set [0\-9a\-f].
98 (The precise range of letters in these two sets varies across UNIX
104 constitute a BSD pseudoterminal pair.
105 A process finds an unused pseudoterminal pair by trying to
107 each pseudoterminal master until an open succeeds.
108 The corresponding pseudoterminal slave (substitute "tty"
109 for "pty" in the name of the master) can then be opened.
113 UNIX 98 master clone device
116 UNIX 98 slave devices
118 .I /dev/pty[p\-za\-e][0\-9a\-f]
121 .I /dev/tty[p\-za\-e][0\-9a\-f]
124 Pseudoterminals are used by applications such as network login services
125 .RB ( ssh "(1), " rlogin "(1), " telnet (1)),
126 terminal emulators such as
138 which controls packet mode operation, can be found in
149 have not been implemented under Linux.