]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man7/pty.7
Wrapped long lines, wrapped at sentence boundaries; stripped trailing
[thirdparty/man-pages.git] / man7 / pty.7
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.
13 .\"
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.
18 .\"
19 .\" Formatted or processed versions of this manual, if unaccompanied by
20 .\" the source, must acknowledge the copyright and authors of this work.
21 .\"
22 .TH PTY 7 2005-10-10 "Linux 2.6.14" "Linux Programmer's Manual"
23 .SH NAME
24 pty \- pseudo-terminal interfaces
25 .SH DESCRIPTION
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
29 .IR master ;
30 the other end is called the
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.
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
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,
56 and this API should be employed in all new programs that use
57 pseudo-terminals.
58
59 Linux provides both BSD-style and (standardised) System V-style
60 pseudo-terminals.
61 System V-style terminals are commonly called Unix 98 pseudo-terminals
62 on Linux systems.
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
68 .BR posix_openpt (3).
69 (This function opens the master clone device,
70 .IR /dev/ptmx ;
71 see
72 .BR pts (4).)
73 After performing any program-specific initialisations,
74 changing the ownership and permissions of the slave device using
75 .BR grantpt (3),
76 and unlocking the slave using
77 .BR unlockpt (3)),
78 the corresponding slave device can be opened by passing
79 the name returned by
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
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
96 .BR proc (5).
97 .SS "BSD pseudo-terminals"
98 BSD-style pseudo-terminals are provided as pre-created pairs, with
99 names of the form
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].
106 (The precise range of letters in these two sets varies across Unix
107 implementations.)
108 For example,
109 .I /dev/ptyp1
110 and
111 .I /dev/ttyp1
112 constitute a BSD pseudo-terminal pair.
113 A process finds an unused pseudo-terminal pair by trying to
114 .BR open (2)
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.
118 .SH "NOTES"
119 A description of the
120 .B TIOCPKT
121 .BR ioctl (),
122 which controls packet mode operation, can be found in
123 .BR tty_ioctl (4).
124
125 The BSD ioctl()s TIOCSTOP, TIOCSTART, TIOCUCNTL, TIOCREMOTE have
126 not been implemented under Linux.
127 .SH "FILES"
128 .I /dev/ptmx
129 (Unix 98 master clone device)
130 .br
131 .I /dev/pts/*
132 (Unix 98 slave devices)
133 .br
134 .I /dev/pty[p-za-e][0-9a-f]
135 (BSD master devices)
136 .br
137 .I /dev/tty[p-za-e][0-9a-f]
138 (BSD slave devices)
139 .I
140 .SH "SEE ALSO"
141 .BR select (2),
142 .BR setsid (2),
143 .BR forkpty (3),
144 .BR openpty (3),
145 .BR termios (3),
146 .BR pts (4),
147 .BR tty (4),
148 .BR tty_ioctl (4)