]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man7/pty.7
user_namespaces.7: wfix
[thirdparty/man-pages.git] / man7 / pty.7
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 2015-07-23 "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 The slave end of the pseudoterminal provides an interface
37 that behaves exactly like a classical terminal.
38 A process that expects to be connected to a terminal,
39 can open the slave end of a pseudoterminal and
40 then be driven by a program that has opened the master end.
41 Anything that is written on the master end is provided to the process
42 on the slave end as though it was input typed on a terminal.
43 For example, writing the interrupt character (usually control-C)
44 to the master device would cause an interrupt signal
45 .RB ( SIGINT )
46 to be generated for the foreground process group
47 that is connected to the slave.
48 Conversely, anything that is written to the slave end of the
49 pseudoterminal can be read by the process that is connected to
50 the master end.
51 Pseudoterminals are used by applications such as network login services
52 .RB ( ssh "(1), " rlogin "(1), " telnet (1)),
53 terminal emulators,
54 .BR script (1),
55 .BR screen (1),
56 and
57 .BR expect (1).
58
59 Data flow between master and slave is handled asynchronously,
60 much like data flow with a physical terminal.
61 Data written to the slave will be available at the master promptly,
62 but may not be available immediately.
63 Similarly, there may be a small processing delay between
64 a write to the master, and the effect being visible at the slave.
65
66 Historically, two pseudoterminal APIs have evolved: BSD and System V.
67 SUSv1 standardized a pseudoterminal API based on the System V API,
68 and this API should be employed in all new programs that use
69 pseudoterminals.
70
71 Linux provides both BSD-style and (standardized) System V-style
72 pseudoterminals.
73 System V-style terminals are commonly called UNIX 98 pseudoterminals
74 on Linux systems.
75 Since kernel 2.6.4, BSD-style pseudoterminals are considered deprecated
76 (they can be disabled when configuring the kernel);
77 UNIX 98 pseudoterminals should be used in new applications.
78 .SS UNIX 98 pseudoterminals
79 An unused UNIX 98 pseudoterminal master is opened by calling
80 .BR posix_openpt (3).
81 (This function opens the master clone device,
82 .IR /dev/ptmx ;
83 see
84 .BR pts (4).)
85 After performing any program-specific initializations,
86 changing the ownership and permissions of the slave device using
87 .BR grantpt (3),
88 and unlocking the slave using
89 .BR unlockpt (3)),
90 the corresponding slave device can be opened by passing
91 the name returned by
92 .BR ptsname (3)
93 in a call to
94 .BR open (2).
95
96 The Linux kernel imposes a limit on the number of available
97 UNIX 98 pseudoterminals.
98 In kernels up to and including 2.6.3, this limit is configured
99 at kernel compilation time
100 .RB ( CONFIG_UNIX98_PTYS ),
101 and the permitted number of pseudoterminals can be up to 2048,
102 with a default setting of 256.
103 Since kernel 2.6.4, the limit is dynamically adjustable via
104 .IR /proc/sys/kernel/pty/max ,
105 and a corresponding file,
106 .IR /proc/sys/kernel/pty/nr ,
107 indicates how many pseudoterminals are currently in use.
108 For further details on these two files, see
109 .BR proc (5).
110 .SS BSD pseudoterminals
111 BSD-style pseudoterminals are provided as precreated pairs, with
112 names of the form
113 .I /dev/ptyXY
114 (master) and
115 .I /dev/ttyXY
116 (slave),
117 where X is a letter from the 16-character set [p-za-e],
118 and Y is a letter from the 16-character set [0-9a-f].
119 (The precise range of letters in these two sets varies across UNIX
120 implementations.)
121 For example,
122 .I /dev/ptyp1
123 and
124 .I /dev/ttyp1
125 constitute a BSD pseudoterminal pair.
126 A process finds an unused pseudoterminal pair by trying to
127 .BR open (2)
128 each pseudoterminal master until an open succeeds.
129 The corresponding pseudoterminal slave (substitute "tty"
130 for "pty" in the name of the master) can then be opened.
131 .SH FILES
132 .I /dev/ptmx
133 (UNIX 98 master clone device)
134 .br
135 .I /dev/pts/*
136 (UNIX 98 slave devices)
137 .br
138 .I /dev/pty[p-za-e][0-9a-f]
139 (BSD master devices)
140 .br
141 .I /dev/tty[p-za-e][0-9a-f]
142 (BSD slave devices)
143 .SH NOTES
144 A description of the
145 .B TIOCPKT
146 .BR ioctl (2),
147 which controls packet mode operation, can be found in
148 .BR tty_ioctl (4).
149
150 The BSD
151 .BR ioctl (2)
152 operations
153 .BR TIOCSTOP ,
154 .BR TIOCSTART ,
155 .BR TIOCUCNTL ,
156 and
157 .BR TIOCREMOTE
158 have not been implemented under Linux.
159 .SH SEE ALSO
160 .BR select (2),
161 .BR setsid (2),
162 .BR forkpty (3),
163 .BR openpty (3),
164 .BR termios (3),
165 .BR pts (4),
166 .BR tty (4),
167 .BR tty_ioctl (4)