1 .\" Hey Emacs! This file is -*- nroff -*- source.
3 .\" Copyright (C) 2005 Michael Kerrisk <mtk-manpages@gmx.net>
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.
19 .\" Formatted or processed versions of this manual, if unaccompanied by
20 .\" the source, must acknowledge the copyright and authors of this work.
22 .TH PTY 7 2005-10-10 "Linux 2.6.14" "Linux Programmer's Manual"
24 pty \- pseudo-terminal interfaces
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
30 the other end is called the
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.
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.
39 For example, writing the interrupt character (usually control-C)
40 to the master device would cause an interrupt signal (SIGINT)
41 to be generated for the foreground process group
42 that is connected to the slave.
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
46 Pseudo-terminals are used by applications such as network login services
47 .RB ( ssh "(1), " rlogin "(1), " telnet (1)),
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,
56 and this API should be employed in all new programs that use
59 Linux provides both BSD-style and (standardised) System V-style
61 System V-style terminals are commonly called Unix 98 pseudo-terminals
63 Since kernel 2.6.4, BSD-style pseudo-terminals are considered deprecated
64 (they can be disabled when configuring the kernel);
65 Unix 98 pseudo-terminals should be used in new applications.
66 .SS "Unix 98 pseudo-terminals"
67 An unused Unix 98 pseudo-terminal master is opened by calling
69 (This function opens the master clone device,
73 After performing any program-specific initialisations,
74 changing the ownership and permissions of the slave device using
76 and unlocking the slave using
78 the corresponding slave device can be opened by passing
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
87 at kernel compilation time (CONFIG_UNIX98_PTYS),
88 and the permitted number of pseudo-terminals can be up to 2048,
89 with a default setting of 256.
90 Since kernel 2.6.4, the limit is dynamically adjustable via
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
97 .SS "BSD pseudo-terminals"
98 BSD-style pseudo-terminals are provided as pre-created pairs, with
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].
106 (The precise range of letters in these two sets varies across Unix
112 constitute a BSD pseudo-terminal pair.
113 A process finds an unused pseudo-terminal pair by trying to
115 each pseudo-terminal master until an open succeeds.
116 The corresponding pseudo-terminal slave (substitute "tty"
117 for "pty" in the name of the master) can then be opened.
120 (Unix 98 master clone device)
123 (Unix 98 slave devices)
125 .I /dev/pty[p-za-e][0-9a-f]
128 .I /dev/tty[p-za-e][0-9a-f]
135 which controls packet mode operation, can be found in
138 The BSD ioctl(2)s TIOCSTOP, TIOCSTART, TIOCUCNTL, TIOCREMOTE have
139 not been implemented under Linux.