1 .\" Hey Emacs! This file is -*- nroff -*- source.
3 .\" Copyright (C) 2005 Michael Kerrisk <mtk.manpages@gmail.com>
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.
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.
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
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
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
25 .TH PTY 7 2005-10-10 "Linux" "Linux Programmer's Manual"
27 pty \- pseudoterminal interfaces
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
34 the other end is called the
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
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
51 Psuedoterminals are used by applications such as network login services
52 .RB ( ssh "(1), " rlogin "(1), " telnet (1)),
59 Historically, two pseudoterminal APIs have evolved: BSD and System V.
60 SUSv1 standardized a pseudoterminal API based on the System V API,
61 and this API should be employed in all new programs that use
64 Linux provides both BSD-style and (standardized) System V-style
66 System V-style terminals are commonly called UNIX 98 pseudoterminals
68 Since kernel 2.6.4, BSD-style pseudoterminals are considered deprecated
69 (they can be disabled when configuring the kernel);
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
74 (This function opens the master clone device,
78 After performing any program-specific initializations,
79 changing the ownership and permissions of the slave device using
81 and unlocking the slave using
83 the corresponding slave device can be opened by passing
89 The Linux kernel imposes a limit on the number of available
90 UNIX 98 pseudoterminals.
91 In kernels up to and including 2.6.3, this limit is configured
92 at kernel compilation time
93 .RB ( CONFIG_UNIX98_PTYS ),
94 and the permitted number of pseudoterminals can be up to 2048,
95 with a default setting of 256.
96 Since kernel 2.6.4, the limit is dynamically adjustable via
97 .IR /proc/sys/kernel/pty/max ,
98 and a corresponding file,
99 .IR /proc/sys/kernel/pty/nr ,
100 indicates how many pseudoterminals are currently in use.
101 For further details on these two files, see
103 .SS "BSD pseudoterminals"
104 BSD-style pseudoterminals are provided as precreated pairs, with
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].
112 (The precise range of letters in these two sets varies across UNIX
118 constitute a BSD pseudoterminal pair.
119 A process finds an unused pseudoterminal pair by trying to
121 each pseudoterminal master until an open succeeds.
122 The corresponding pseudoterminal slave (substitute "tty"
123 for "pty" in the name of the master) can then be opened.
126 (UNIX 98 master clone device)
129 (UNIX 98 slave devices)
131 .I /dev/pty[p-za-e][0-9a-f]
134 .I /dev/tty[p-za-e][0-9a-f]
140 which controls packet mode operation, can be found in
151 have not been implemented under Linux.