]>
Commit | Line | Data |
---|---|---|
c11b1abf | 1 | .\" Copyright (C) 2005 Michael Kerrisk <mtk.manpages@gmail.com> |
1ae9f937 | 2 | .\" |
93015253 | 3 | .\" %%%LICENSE_START(VERBATIM) |
1ae9f937 MK |
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. | |
c13182ef | 12 | .\" |
1ae9f937 MK |
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 | |
10d76543 MK |
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. | |
c13182ef | 20 | .\" |
1ae9f937 MK |
21 | .\" Formatted or processed versions of this manual, if unaccompanied by |
22 | .\" the source, must acknowledge the copyright and authors of this work. | |
4b72fb64 | 23 | .\" %%%LICENSE_END |
1ae9f937 | 24 | .\" |
4b8c67d9 | 25 | .TH PTY 7 2017-09-15 "Linux" "Linux Programmer's Manual" |
1ae9f937 | 26 | .SH NAME |
b218b023 | 27 | pty \- pseudoterminal interfaces |
1ae9f937 | 28 | .SH DESCRIPTION |
b218b023 | 29 | A pseudoterminal (sometimes abbreviated "pty") |
614e4812 | 30 | is a pair of virtual character devices that |
c13182ef MK |
31 | provide a bidirectional communication channel. |
32 | One end of the channel is called the | |
1ae9f937 | 33 | .IR master ; |
c13182ef | 34 | the other end is called the |
1ae9f937 | 35 | .IR slave . |
b218b023 | 36 | The slave end of the pseudoterminal provides an interface |
1ae9f937 MK |
37 | that behaves exactly like a classical terminal. |
38 | A process that expects to be connected to a terminal, | |
b218b023 | 39 | can open the slave end of a pseudoterminal and |
1ae9f937 | 40 | then be driven by a program that has opened the master end. |
c13182ef MK |
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. | |
1ae9f937 | 43 | For example, writing the interrupt character (usually control-C) |
8bd58774 MK |
44 | to the master device would cause an interrupt signal |
45 | .RB ( SIGINT ) | |
c13182ef | 46 | to be generated for the foreground process group |
1ae9f937 | 47 | that is connected to the slave. |
c13182ef | 48 | Conversely, anything that is written to the slave end of the |
b218b023 | 49 | pseudoterminal can be read by the process that is connected to |
1ae9f937 | 50 | the master end. |
40a1b471 | 51 | Pseudoterminals are used by applications such as network login services |
1ae9f937 | 52 | .RB ( ssh "(1), " rlogin "(1), " telnet (1)), |
1848bcfb MK |
53 | terminal emulators such as |
54 | .BR xterm (1), | |
1ae9f937 MK |
55 | .BR script (1), |
56 | .BR screen (1), | |
1848bcfb MK |
57 | .BR tmux (1), |
58 | .BR unbuffer (1), | |
1ae9f937 MK |
59 | and |
60 | .BR expect (1). | |
a721e8b2 | 61 | .PP |
60b3b93c MK |
62 | Data flow between master and slave is handled asynchronously, |
63 | much like data flow with a physical terminal. | |
64 | Data written to the slave will be available at the master promptly, | |
65 | but may not be available immediately. | |
66 | Similarly, there may be a small processing delay between | |
4b063769 | 67 | a write to the master, and the effect being visible at the slave. |
a721e8b2 | 68 | .PP |
b218b023 MK |
69 | Historically, two pseudoterminal APIs have evolved: BSD and System V. |
70 | SUSv1 standardized a pseudoterminal API based on the System V API, | |
c13182ef | 71 | and this API should be employed in all new programs that use |
b218b023 | 72 | pseudoterminals. |
a721e8b2 | 73 | .PP |
d9bfdb9c | 74 | Linux provides both BSD-style and (standardized) System V-style |
b218b023 MK |
75 | pseudoterminals. |
76 | System V-style terminals are commonly called UNIX 98 pseudoterminals | |
1ae9f937 | 77 | on Linux systems. |
b218b023 | 78 | Since kernel 2.6.4, BSD-style pseudoterminals are considered deprecated |
c13182ef | 79 | (they can be disabled when configuring the kernel); |
b218b023 | 80 | UNIX 98 pseudoterminals should be used in new applications. |
73d8cece | 81 | .SS UNIX 98 pseudoterminals |
b218b023 | 82 | An unused UNIX 98 pseudoterminal master is opened by calling |
1ae9f937 MK |
83 | .BR posix_openpt (3). |
84 | (This function opens the master clone device, | |
c13182ef MK |
85 | .IR /dev/ptmx ; |
86 | see | |
5872bd2f | 87 | .BR pts (4).) |
d9bfdb9c | 88 | After performing any program-specific initializations, |
c13182ef | 89 | changing the ownership and permissions of the slave device using |
1ae9f937 | 90 | .BR grantpt (3), |
c13182ef | 91 | and unlocking the slave using |
1ae9f937 MK |
92 | .BR unlockpt (3)), |
93 | the corresponding slave device can be opened by passing | |
c13182ef | 94 | the name returned by |
1ae9f937 MK |
95 | .BR ptsname (3) |
96 | in a call to | |
97 | .BR open (2). | |
a721e8b2 | 98 | .PP |
1ae9f937 | 99 | The Linux kernel imposes a limit on the number of available |
b218b023 | 100 | UNIX 98 pseudoterminals. |
1ae9f937 | 101 | In kernels up to and including 2.6.3, this limit is configured |
47433403 MK |
102 | at kernel compilation time |
103 | .RB ( CONFIG_UNIX98_PTYS ), | |
b218b023 | 104 | and the permitted number of pseudoterminals can be up to 2048, |
1ae9f937 | 105 | with a default setting of 256. |
c13182ef | 106 | Since kernel 2.6.4, the limit is dynamically adjustable via |
1ae9f937 MK |
107 | .IR /proc/sys/kernel/pty/max , |
108 | and a corresponding file, | |
109 | .IR /proc/sys/kernel/pty/nr , | |
b218b023 | 110 | indicates how many pseudoterminals are currently in use. |
1ae9f937 MK |
111 | For further details on these two files, see |
112 | .BR proc (5). | |
73d8cece | 113 | .SS BSD pseudoterminals |
b218b023 | 114 | BSD-style pseudoterminals are provided as precreated pairs, with |
c13182ef | 115 | names of the form |
1ae9f937 MK |
116 | .I /dev/ptyXY |
117 | (master) and | |
118 | .I /dev/ttyXY | |
119 | (slave), | |
9bc87ed0 MK |
120 | where X is a letter from the 16-character set [p\-za\-e], |
121 | and Y is a letter from the 16-character set [0\-9a\-f]. | |
008f1ecc | 122 | (The precise range of letters in these two sets varies across UNIX |
1ae9f937 MK |
123 | implementations.) |
124 | For example, | |
125 | .I /dev/ptyp1 | |
126 | and | |
127 | .I /dev/ttyp1 | |
b218b023 MK |
128 | constitute a BSD pseudoterminal pair. |
129 | A process finds an unused pseudoterminal pair by trying to | |
1ae9f937 | 130 | .BR open (2) |
b218b023 MK |
131 | each pseudoterminal master until an open succeeds. |
132 | The corresponding pseudoterminal slave (substitute "tty" | |
1ae9f937 | 133 | for "pty" in the name of the master) can then be opened. |
47297adb | 134 | .SH FILES |
6f9c4ef2 | 135 | .TP |
c13182ef | 136 | .I /dev/ptmx |
6f9c4ef2 MK |
137 | UNIX 98 master clone device |
138 | .TP | |
1ae9f937 | 139 | .I /dev/pts/* |
6f9c4ef2 MK |
140 | UNIX 98 slave devices |
141 | .TP | |
9bc87ed0 | 142 | .I /dev/pty[p\-za\-e][0\-9a\-f] |
6f9c4ef2 MK |
143 | BSD master devices |
144 | .TP | |
9bc87ed0 | 145 | .I /dev/tty[p\-za\-e][0\-9a\-f] |
6f9c4ef2 | 146 | BSD slave devices |
47297adb | 147 | .SH NOTES |
2b2581ee MK |
148 | A description of the |
149 | .B TIOCPKT | |
150 | .BR ioctl (2), | |
151 | which controls packet mode operation, can be found in | |
a9168840 | 152 | .BR ioctl_tty (2). |
a721e8b2 | 153 | .PP |
47433403 MK |
154 | The BSD |
155 | .BR ioctl (2) | |
156 | operations | |
157 | .BR TIOCSTOP , | |
158 | .BR TIOCSTART , | |
159 | .BR TIOCUCNTL , | |
160 | and | |
161 | .BR TIOCREMOTE | |
162 | have not been implemented under Linux. | |
47297adb | 163 | .SH SEE ALSO |
a9168840 | 164 | .BR ioctl_tty (2), |
1ae9f937 MK |
165 | .BR select (2), |
166 | .BR setsid (2), | |
167 | .BR forkpty (3), | |
168 | .BR openpty (3), | |
169 | .BR termios (3), | |
5872bd2f | 170 | .BR pts (4), |
a9168840 | 171 | .BR tty (4) |