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