share/mk/: build-pdf-book: Fix chapter bookmarks
[man-pages.git] / man7 / pty.7
blob7f47ce550ee542c55901a98a61642991faaf064f
1 .\" Copyright (C) 2005 Michael Kerrisk <mtk.manpages@gmail.com>
2 .\"
3 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
4 .\"
5 .TH pty 7 (date) "Linux man-pages (unreleased)"
6 .SH NAME
7 pty \- pseudoterminal interfaces
8 .SH DESCRIPTION
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
13 .IR master ;
14 the other end is called the
15 .IR slave .
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
26 .RB ( SIGINT )
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
31 the master end.
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
43 pseudoterminals.
45 Linux provides both BSD-style and (standardized) System V-style
46 pseudoterminals.
47 System V-style terminals are commonly called UNIX 98 pseudoterminals
48 on Linux systems.
50 Since Linux 2.6.4, BSD-style pseudoterminals are considered deprecated:
51 support can be disabled when building the kernel by disabling the
52 .B CONFIG_LEGACY_PTYS
53 option.
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
59 .BR posix_openpt (3).
60 (This function opens the master clone device,
61 .IR /dev/ptmx ;
62 see
63 .BR pts (4).)
64 After performing any program-specific initializations,
65 changing the ownership and permissions of the slave device using
66 .BR grantpt (3),
67 and unlocking the slave using
68 .BR unlockpt (3)),
69 the corresponding slave device can be opened by passing
70 the name returned by
71 .BR ptsname (3)
72 in a call to
73 .BR open (2).
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
88 .BR proc (5).
89 .SS BSD pseudoterminals
90 BSD-style pseudoterminals are provided as precreated pairs, with
91 names of the form
92 .I /dev/ptyXY
93 (master) and
94 .I /dev/ttyXY
95 (slave),
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
99 implementations.)
100 For example,
101 .I /dev/ptyp1
103 .I /dev/ttyp1
104 constitute a BSD pseudoterminal pair.
105 A process finds an unused pseudoterminal pair by trying to
106 .BR open (2)
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.
110 .SH FILES
112 .I /dev/ptmx
113 UNIX 98 master clone device
115 .I /dev/pts/*
116 UNIX 98 slave devices
118 .I /dev/pty[p\-za\-e][0\-9a\-f]
119 BSD master devices
121 .I /dev/tty[p\-za\-e][0\-9a\-f]
122 BSD slave devices
123 .SH NOTES
124 Pseudoterminals are used by applications such as network login services
126 .BR ssh (1),
127 .BR rlogin (1),
128 .BR telnet (1)),
129 terminal emulators such as
130 .BR xterm (1),
131 .BR script (1),
132 .BR screen (1),
133 .BR tmux (1),
134 .BR unbuffer (1),
136 .BR expect (1).
138 A description of the
139 .B TIOCPKT
140 .BR ioctl (2),
141 which controls packet mode operation, can be found in
142 .BR ioctl_tty (2).
144 The BSD
145 .BR ioctl (2)
146 operations
147 .BR TIOCSTOP ,
148 .BR TIOCSTART ,
149 .BR TIOCUCNTL ,
151 .B TIOCREMOTE
152 have not been implemented under Linux.
153 .SH SEE ALSO
154 .BR ioctl_tty (2),
155 .BR select (2),
156 .BR setsid (2),
157 .BR forkpty (3),
158 .BR openpty (3),
159 .BR termios (3),
160 .BR pts (4),
161 .BR tty (4)