]>
Commit | Line | Data |
---|---|---|
1ae9f937 MK |
1 | .\" Hey Emacs! This file is -*- nroff -*- source. |
2 | .\" | |
3 | .\" Copyright (C) 2005 Michael Kerrisk <mtk-manpages@gmx.net> | |
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 | |
c13182ef MK |
17 | .\" the use of the information contained herein. |
18 | .\" | |
1ae9f937 MK |
19 | .\" Formatted or processed versions of this manual, if unaccompanied by |
20 | .\" the source, must acknowledge the copyright and authors of this work. | |
21 | .\" | |
d9343c5c | 22 | .TH PTY 7 2005-10-10 "Linux" "Linux Programmer's Manual" |
1ae9f937 | 23 | .SH NAME |
3a20b4ca | 24 | pty \- pseudo-terminal interfaces |
1ae9f937 | 25 | .SH DESCRIPTION |
c13182ef MK |
26 | A pseudo-terminal is a pair of virtual character devices that |
27 | provide a bidirectional communication channel. | |
28 | One end of the channel is called the | |
1ae9f937 | 29 | .IR master ; |
c13182ef | 30 | the other end is called the |
1ae9f937 MK |
31 | .IR slave . |
32 | The slave end of the pseudo-terminal provides an interface | |
33 | that behaves exactly like a classical terminal. | |
34 | A process that expects to be connected to a terminal, | |
35 | can open the slave end of a pseudo-terminal and | |
36 | then be driven by a program that has opened the master end. | |
c13182ef MK |
37 | Anything that is written on the master end is provided to the process |
38 | on the slave end as though it was input typed on a terminal. | |
1ae9f937 MK |
39 | For example, writing the interrupt character (usually control-C) |
40 | to the master device would cause an interrupt signal (SIGINT) | |
c13182ef | 41 | to be generated for the foreground process group |
1ae9f937 | 42 | that is connected to the slave. |
c13182ef MK |
43 | Conversely, anything that is written to the slave end of the |
44 | pseudo-terminal can be read by the process that is connected to | |
1ae9f937 MK |
45 | the master end. |
46 | Pseudo-terminals are used by applications such as network login services | |
47 | .RB ( ssh "(1), " rlogin "(1), " telnet (1)), | |
48 | terminal emulators, | |
49 | .BR script (1), | |
50 | .BR screen (1), | |
51 | and | |
52 | .BR expect (1). | |
53 | ||
54 | Historically, two pseudo-terminal APIs have evolved: BSD and System V. | |
55 | SUSv1 standardized a pseudo-terminal API based on the System V API, | |
c13182ef | 56 | and this API should be employed in all new programs that use |
1ae9f937 MK |
57 | pseudo-terminals. |
58 | ||
c13182ef | 59 | Linux provides both BSD-style and (standardised) System V-style |
1ae9f937 | 60 | pseudo-terminals. |
c13182ef | 61 | System V-style terminals are commonly called Unix 98 pseudo-terminals |
1ae9f937 MK |
62 | on Linux systems. |
63 | Since kernel 2.6.4, BSD-style pseudo-terminals are considered deprecated | |
c13182ef | 64 | (they can be disabled when configuring the kernel); |
1ae9f937 MK |
65 | Unix 98 pseudo-terminals should be used in new applications. |
66 | .SS "Unix 98 pseudo-terminals" | |
c13182ef | 67 | An unused Unix 98 pseudo-terminal master is opened by calling |
1ae9f937 MK |
68 | .BR posix_openpt (3). |
69 | (This function opens the master clone device, | |
c13182ef MK |
70 | .IR /dev/ptmx ; |
71 | see | |
5872bd2f | 72 | .BR pts (4).) |
1ae9f937 | 73 | After performing any program-specific initialisations, |
c13182ef | 74 | changing the ownership and permissions of the slave device using |
1ae9f937 | 75 | .BR grantpt (3), |
c13182ef | 76 | and unlocking the slave using |
1ae9f937 MK |
77 | .BR unlockpt (3)), |
78 | the corresponding slave device can be opened by passing | |
c13182ef | 79 | the name returned by |
1ae9f937 MK |
80 | .BR ptsname (3) |
81 | in a call to | |
82 | .BR open (2). | |
83 | ||
84 | The Linux kernel imposes a limit on the number of available | |
85 | Unix 98 pseudo-terminals. | |
86 | In kernels up to and including 2.6.3, this limit is configured | |
c13182ef | 87 | at kernel compilation time (CONFIG_UNIX98_PTYS), |
1ae9f937 MK |
88 | and the permitted number of pseudo-terminals can be up to 2048, |
89 | with a default setting of 256. | |
c13182ef | 90 | Since kernel 2.6.4, the limit is dynamically adjustable via |
1ae9f937 MK |
91 | .IR /proc/sys/kernel/pty/max , |
92 | and a corresponding file, | |
93 | .IR /proc/sys/kernel/pty/nr , | |
94 | indicates how many pseudo-terminals are currently in use. | |
95 | For further details on these two files, see | |
96 | .BR proc (5). | |
97 | .SS "BSD pseudo-terminals" | |
98 | BSD-style pseudo-terminals are provided as pre-created pairs, with | |
c13182ef | 99 | names of the form |
1ae9f937 MK |
100 | .I /dev/ptyXY |
101 | (master) and | |
102 | .I /dev/ttyXY | |
103 | (slave), | |
104 | where X is a letter from the 16-character set [p-za-e], | |
105 | and Y is a letter from the 16-character set [0-9a-f]. | |
c13182ef | 106 | (The precise range of letters in these two sets varies across Unix |
1ae9f937 MK |
107 | implementations.) |
108 | For example, | |
109 | .I /dev/ptyp1 | |
110 | and | |
111 | .I /dev/ttyp1 | |
112 | constitute a BSD pseudo-terminal pair. | |
c13182ef | 113 | A process finds an unused pseudo-terminal pair by trying to |
1ae9f937 MK |
114 | .BR open (2) |
115 | each pseudo-terminal master until an open succeeds. | |
c13182ef | 116 | The corresponding pseudo-terminal slave (substitute "tty" |
1ae9f937 | 117 | for "pty" in the name of the master) can then be opened. |
1ae9f937 | 118 | .SH "FILES" |
c13182ef | 119 | .I /dev/ptmx |
1ae9f937 MK |
120 | (Unix 98 master clone device) |
121 | .br | |
122 | .I /dev/pts/* | |
123 | (Unix 98 slave devices) | |
124 | .br | |
c13182ef | 125 | .I /dev/pty[p-za-e][0-9a-f] |
1ae9f937 MK |
126 | (BSD master devices) |
127 | .br | |
c13182ef | 128 | .I /dev/tty[p-za-e][0-9a-f] |
1ae9f937 MK |
129 | (BSD slave devices) |
130 | .I | |
2b2581ee MK |
131 | .SH "NOTES" |
132 | A description of the | |
133 | .B TIOCPKT | |
134 | .BR ioctl (2), | |
135 | which controls packet mode operation, can be found in | |
136 | .BR tty_ioctl (4). | |
137 | ||
138 | The BSD ioctl(2)s TIOCSTOP, TIOCSTART, TIOCUCNTL, TIOCREMOTE have | |
139 | not been implemented under Linux. | |
1ae9f937 MK |
140 | .SH "SEE ALSO" |
141 | .BR select (2), | |
142 | .BR setsid (2), | |
143 | .BR forkpty (3), | |
144 | .BR openpty (3), | |
145 | .BR termios (3), | |
5872bd2f | 146 | .BR pts (4), |
1ae9f937 MK |
147 | .BR tty (4), |
148 | .BR tty_ioctl (4) |