]>
Commit | Line | Data |
---|---|---|
1ae9f937 MK |
1 | .\" Hey Emacs! This file is -*- nroff -*- source. |
2 | .\" | |
c11b1abf | 3 | .\" Copyright (C) 2005 Michael Kerrisk <mtk.manpages@gmail.com> |
1ae9f937 MK |
4 | .\" |
5 | .\" Permission is granted to make and distribute verbatim copies of this | |
6 | .\" manual provided the copyright notice and this permission notice are | |
7 | .\" preserved on all copies. | |
8 | .\" | |
9 | .\" Permission is granted to copy and distribute modified versions of this | |
10 | .\" manual under the conditions for verbatim copying, provided that the | |
11 | .\" entire resulting derived work is distributed under the terms of a | |
12 | .\" permission notice identical to this one. | |
c13182ef | 13 | .\" |
1ae9f937 MK |
14 | .\" Since the Linux kernel and libraries are constantly changing, this |
15 | .\" manual page may be incorrect or out-of-date. The author(s) assume no | |
16 | .\" responsibility for errors or omissions, or for damages resulting from | |
10d76543 MK |
17 | .\" the use of the information contained herein. The author(s) may not |
18 | .\" have taken the same level of care in the production of this manual, | |
19 | .\" which is licensed free of charge, as they might when working | |
20 | .\" professionally. | |
c13182ef | 21 | .\" |
1ae9f937 MK |
22 | .\" Formatted or processed versions of this manual, if unaccompanied by |
23 | .\" the source, must acknowledge the copyright and authors of this work. | |
24 | .\" | |
d9343c5c | 25 | .TH PTY 7 2005-10-10 "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. |
662b2137 | 51 | Psuedoterminals are used by applications such as network login services |
1ae9f937 MK |
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 | ||
b218b023 MK |
59 | Historically, two pseudoterminal APIs have evolved: BSD and System V. |
60 | SUSv1 standardized a pseudoterminal API based on the System V API, | |
c13182ef | 61 | and this API should be employed in all new programs that use |
b218b023 | 62 | pseudoterminals. |
1ae9f937 | 63 | |
d9bfdb9c | 64 | Linux provides both BSD-style and (standardized) System V-style |
b218b023 MK |
65 | pseudoterminals. |
66 | System V-style terminals are commonly called UNIX 98 pseudoterminals | |
1ae9f937 | 67 | on Linux systems. |
b218b023 | 68 | Since kernel 2.6.4, BSD-style pseudoterminals are considered deprecated |
c13182ef | 69 | (they can be disabled when configuring the kernel); |
b218b023 MK |
70 | UNIX 98 pseudoterminals should be used in new applications. |
71 | .SS "UNIX 98 pseudoterminals" | |
72 | An unused UNIX 98 pseudoterminal master is opened by calling | |
1ae9f937 MK |
73 | .BR posix_openpt (3). |
74 | (This function opens the master clone device, | |
c13182ef MK |
75 | .IR /dev/ptmx ; |
76 | see | |
5872bd2f | 77 | .BR pts (4).) |
d9bfdb9c | 78 | After performing any program-specific initializations, |
c13182ef | 79 | changing the ownership and permissions of the slave device using |
1ae9f937 | 80 | .BR grantpt (3), |
c13182ef | 81 | and unlocking the slave using |
1ae9f937 MK |
82 | .BR unlockpt (3)), |
83 | the corresponding slave device can be opened by passing | |
c13182ef | 84 | the name returned by |
1ae9f937 MK |
85 | .BR ptsname (3) |
86 | in a call to | |
87 | .BR open (2). | |
88 | ||
89 | The Linux kernel imposes a limit on the number of available | |
b218b023 | 90 | UNIX 98 pseudoterminals. |
1ae9f937 | 91 | In kernels up to and including 2.6.3, this limit is configured |
47433403 MK |
92 | at kernel compilation time |
93 | .RB ( CONFIG_UNIX98_PTYS ), | |
b218b023 | 94 | and the permitted number of pseudoterminals can be up to 2048, |
1ae9f937 | 95 | with a default setting of 256. |
c13182ef | 96 | Since kernel 2.6.4, the limit is dynamically adjustable via |
1ae9f937 MK |
97 | .IR /proc/sys/kernel/pty/max , |
98 | and a corresponding file, | |
99 | .IR /proc/sys/kernel/pty/nr , | |
b218b023 | 100 | indicates how many pseudoterminals are currently in use. |
1ae9f937 MK |
101 | For further details on these two files, see |
102 | .BR proc (5). | |
b218b023 MK |
103 | .SS "BSD pseudoterminals" |
104 | BSD-style pseudoterminals are provided as precreated pairs, with | |
c13182ef | 105 | names of the form |
1ae9f937 MK |
106 | .I /dev/ptyXY |
107 | (master) and | |
108 | .I /dev/ttyXY | |
109 | (slave), | |
110 | where X is a letter from the 16-character set [p-za-e], | |
111 | and Y is a letter from the 16-character set [0-9a-f]. | |
008f1ecc | 112 | (The precise range of letters in these two sets varies across UNIX |
1ae9f937 MK |
113 | implementations.) |
114 | For example, | |
115 | .I /dev/ptyp1 | |
116 | and | |
117 | .I /dev/ttyp1 | |
b218b023 MK |
118 | constitute a BSD pseudoterminal pair. |
119 | A process finds an unused pseudoterminal pair by trying to | |
1ae9f937 | 120 | .BR open (2) |
b218b023 MK |
121 | each pseudoterminal master until an open succeeds. |
122 | The corresponding pseudoterminal slave (substitute "tty" | |
1ae9f937 | 123 | for "pty" in the name of the master) can then be opened. |
1ae9f937 | 124 | .SH "FILES" |
c13182ef | 125 | .I /dev/ptmx |
008f1ecc | 126 | (UNIX 98 master clone device) |
1ae9f937 MK |
127 | .br |
128 | .I /dev/pts/* | |
008f1ecc | 129 | (UNIX 98 slave devices) |
1ae9f937 | 130 | .br |
c13182ef | 131 | .I /dev/pty[p-za-e][0-9a-f] |
1ae9f937 MK |
132 | (BSD master devices) |
133 | .br | |
c13182ef | 134 | .I /dev/tty[p-za-e][0-9a-f] |
1ae9f937 | 135 | (BSD slave devices) |
2b2581ee MK |
136 | .SH "NOTES" |
137 | A description of the | |
138 | .B TIOCPKT | |
139 | .BR ioctl (2), | |
140 | which controls packet mode operation, can be found in | |
141 | .BR tty_ioctl (4). | |
142 | ||
47433403 MK |
143 | The BSD |
144 | .BR ioctl (2) | |
145 | operations | |
146 | .BR TIOCSTOP , | |
147 | .BR TIOCSTART , | |
148 | .BR TIOCUCNTL , | |
149 | and | |
150 | .BR TIOCREMOTE | |
151 | have not been implemented under Linux. | |
1ae9f937 MK |
152 | .SH "SEE ALSO" |
153 | .BR select (2), | |
154 | .BR setsid (2), | |
155 | .BR forkpty (3), | |
156 | .BR openpty (3), | |
157 | .BR termios (3), | |
5872bd2f | 158 | .BR pts (4), |
1ae9f937 MK |
159 | .BR tty (4), |
160 | .BR tty_ioctl (4) |