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 \- psuedoterminal interfaces
29 A psuedoterminal is a pair of virtual character devices that
30 provide a bidirectional communication channel.
31 One end of the channel is called the
33 the other end is called the
35 The slave end of the psuedoterminal provides an interface
36 that behaves exactly like a classical terminal.
37 A process that expects to be connected to a terminal,
38 can open the slave end of a psuedoterminal and
39 then be driven by a program that has opened the master end.
40 Anything that is written on the master end is provided to the process
41 on the slave end as though it was input typed on a terminal.
42 For example, writing the interrupt character (usually control-C)
43 to the master device would cause an interrupt signal
45 to be generated for the foreground process group
46 that is connected to the slave.
47 Conversely, anything that is written to the slave end of the
48 psuedoterminal can be read by the process that is connected to
50 Psuedoterminals are used by applications such as network login services
51 .RB ( ssh "(1), " rlogin "(1), " telnet (1)),
58 Historically, two psuedoterminal APIs have evolved: BSD and System V.
59 SUSv1 standardized a psuedoterminal API based on the System V API,
60 and this API should be employed in all new programs that use
63 Linux provides both BSD-style and (standardized) System V-style
65 System V-style terminals are commonly called UNIX 98 psuedoterminals
67 Since kernel 2.6.4, BSD-style psuedoterminals are considered deprecated
68 (they can be disabled when configuring the kernel);
69 UNIX 98 psuedoterminals should be used in new applications.
70 .SS "UNIX 98 psuedoterminals"
71 An unused UNIX 98 psuedoterminal master is opened by calling
73 (This function opens the master clone device,
77 After performing any program-specific initializations,
78 changing the ownership and permissions of the slave device using
80 and unlocking the slave using
82 the corresponding slave device can be opened by passing
88 The Linux kernel imposes a limit on the number of available
89 UNIX 98 psuedoterminals.
90 In kernels up to and including 2.6.3, this limit is configured
91 at kernel compilation time
92 .RB ( CONFIG_UNIX98_PTYS ),
93 and the permitted number of psuedoterminals can be up to 2048,
94 with a default setting of 256.
95 Since kernel 2.6.4, the limit is dynamically adjustable via
96 .IR /proc/sys/kernel/pty/max ,
97 and a corresponding file,
98 .IR /proc/sys/kernel/pty/nr ,
99 indicates how many psuedoterminals are currently in use.
100 For further details on these two files, see
102 .SS "BSD psuedoterminals"
103 BSD-style psuedoterminals are provided as precreated pairs, with
109 where X is a letter from the 16-character set [p-za-e],
110 and Y is a letter from the 16-character set [0-9a-f].
111 (The precise range of letters in these two sets varies across UNIX
117 constitute a BSD psuedoterminal pair.
118 A process finds an unused psuedoterminal pair by trying to
120 each psuedoterminal master until an open succeeds.
121 The corresponding psuedoterminal slave (substitute "tty"
122 for "pty" in the name of the master) can then be opened.
125 (UNIX 98 master clone device)
128 (UNIX 98 slave devices)
130 .I /dev/pty[p-za-e][0-9a-f]
133 .I /dev/tty[p-za-e][0-9a-f]
139 which controls packet mode operation, can be found in
150 have not been implemented under Linux.