proc.5: Remove duplicated /proc/[pid]/gid_map entry
[man-pages.git] / man7 / pty.7
blobbef36643b5e7273217008724714fdb186bea97cc
1 .\" Copyright (C) 2005 Michael Kerrisk <mtk.manpages@gmail.com>
2 .\"
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein.  The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .TH PTY 7 2020-08-13 "Linux" "Linux Programmer's Manual"
26 .SH NAME
27 pty \- pseudoterminal interfaces
28 .SH DESCRIPTION
29 A pseudoterminal (sometimes abbreviated "pty")
30 is a pair of virtual character devices that
31 provide a bidirectional communication channel.
32 One end of the channel is called the
33 .IR master ;
34 the other end is called the
35 .IR slave .
36 .PP
37 The slave end of the pseudoterminal provides an interface
38 that behaves exactly like a classical terminal.
39 A process that expects to be connected to a terminal,
40 can open the slave end of a pseudoterminal and
41 then be driven by a program that has opened the master end.
42 Anything that is written on the master end is provided to the process
43 on the slave end as though it was input typed on a terminal.
44 For example, writing the interrupt character (usually control-C)
45 to the master device would cause an interrupt signal
46 .RB ( SIGINT )
47 to be generated for the foreground process group
48 that is connected to the slave.
49 Conversely, anything that is written to the slave end of the
50 pseudoterminal can be read by the process that is connected to
51 the master end.
52 .PP
53 Data flow between master and slave is handled asynchronously,
54 much like data flow with a physical terminal.
55 Data written to the slave will be available at the master promptly,
56 but may not be available immediately.
57 Similarly, there may be a small processing delay between
58 a write to the master, and the effect being visible at the slave.
59 .PP
60 Historically, two pseudoterminal APIs have evolved: BSD and System V.
61 SUSv1 standardized a pseudoterminal API based on the System V API,
62 and this API should be employed in all new programs that use
63 pseudoterminals.
64 .PP
65 Linux provides both BSD-style and (standardized) System V-style
66 pseudoterminals.
67 System V-style terminals are commonly called UNIX 98 pseudoterminals
68 on Linux systems.
69 .PP
70 Since kernel 2.6.4, BSD-style pseudoterminals are considered deprecated:
71 support can be disabled when building the kernel by disabling the
72 .B CONFIG_LEGACY_PTYS
73 option.
74 (Starting with Linux 2.6.30,
75 that option is disabled by default in the mainline kernel.)
76 UNIX 98 pseudoterminals should be used in new applications.
77 .SS UNIX 98 pseudoterminals
78 An unused UNIX 98 pseudoterminal master is opened by calling
79 .BR posix_openpt (3).
80 (This function opens the master clone device,
81 .IR /dev/ptmx ;
82 see
83 .BR pts (4).)
84 After performing any program-specific initializations,
85 changing the ownership and permissions of the slave device using
86 .BR grantpt (3),
87 and unlocking the slave using
88 .BR unlockpt (3)),
89 the corresponding slave device can be opened by passing
90 the name returned by
91 .BR ptsname (3)
92 in a call to
93 .BR open (2).
94 .PP
95 The Linux kernel imposes a limit on the number of available
96 UNIX 98 pseudoterminals.
97 In kernels up to and including 2.6.3, this limit is configured
98 at kernel compilation time
99 .RB ( CONFIG_UNIX98_PTYS ),
100 and the permitted number of pseudoterminals can be up to 2048,
101 with a default setting of 256.
102 Since kernel 2.6.4, the limit is dynamically adjustable via
103 .IR /proc/sys/kernel/pty/max ,
104 and a corresponding file,
105 .IR /proc/sys/kernel/pty/nr ,
106 indicates how many pseudoterminals are currently in use.
107 For further details on these two files, see
108 .BR proc (5).
109 .SS BSD pseudoterminals
110 BSD-style pseudoterminals are provided as precreated pairs, with
111 names of the form
112 .I /dev/ptyXY
113 (master) and
114 .I /dev/ttyXY
115 (slave),
116 where X is a letter from the 16-character set [p\-za\-e],
117 and Y is a letter from the 16-character set [0\-9a\-f].
118 (The precise range of letters in these two sets varies across UNIX
119 implementations.)
120 For example,
121 .I /dev/ptyp1
123 .I /dev/ttyp1
124 constitute a BSD pseudoterminal pair.
125 A process finds an unused pseudoterminal pair by trying to
126 .BR open (2)
127 each pseudoterminal master until an open succeeds.
128 The corresponding pseudoterminal slave (substitute "tty"
129 for "pty" in the name of the master) can then be opened.
130 .SH FILES
132 .I /dev/ptmx
133 UNIX 98 master clone device
135 .I /dev/pts/*
136 UNIX 98 slave devices
138 .I /dev/pty[p\-za\-e][0\-9a\-f]
139 BSD master devices
141 .I /dev/tty[p\-za\-e][0\-9a\-f]
142 BSD slave devices
143 .SH NOTES
144 Pseudoterminals are used by applications such as network login services
145 .RB ( ssh "(1), " rlogin "(1), " telnet (1)),
146 terminal emulators such as
147 .BR xterm (1),
148 .BR script (1),
149 .BR screen (1),
150 .BR tmux (1),
151 .BR unbuffer (1),
153 .BR expect (1).
155 A description of the
156 .B TIOCPKT
157 .BR ioctl (2),
158 which controls packet mode operation, can be found in
159 .BR ioctl_tty (2).
161 The BSD
162 .BR ioctl (2)
163 operations
164 .BR TIOCSTOP ,
165 .BR TIOCSTART ,
166 .BR TIOCUCNTL ,
168 .BR TIOCREMOTE
169 have not been implemented under Linux.
170 .SH SEE ALSO
171 .BR ioctl_tty (2),
172 .BR select (2),
173 .BR setsid (2),
174 .BR forkpty (3),
175 .BR openpty (3),
176 .BR termios (3),
177 .BR pts (4),
178 .BR tty (4)