]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man7/pty.7
sched.7: Minor wording improvement in text introducing system calls
[thirdparty/man-pages.git] / man7 / pty.7
CommitLineData
c11b1abf 1.\" Copyright (C) 2005 Michael Kerrisk <mtk.manpages@gmail.com>
1ae9f937 2.\"
93015253 3.\" %%%LICENSE_START(VERBATIM)
1ae9f937
MK
4.\" Permission is granted to make and distribute verbatim copies of this
5.\" manual provided the copyright notice and this permission notice are
6.\" preserved on all copies.
7.\"
8.\" Permission is granted to copy and distribute modified versions of this
9.\" manual under the conditions for verbatim copying, provided that the
10.\" entire resulting derived work is distributed under the terms of a
11.\" permission notice identical to this one.
c13182ef 12.\"
1ae9f937
MK
13.\" Since the Linux kernel and libraries are constantly changing, this
14.\" manual page may be incorrect or out-of-date. The author(s) assume no
15.\" responsibility for errors or omissions, or for damages resulting from
10d76543
MK
16.\" the use of the information contained herein. The author(s) may not
17.\" have taken the same level of care in the production of this manual,
18.\" which is licensed free of charge, as they might when working
19.\" professionally.
c13182ef 20.\"
1ae9f937
MK
21.\" Formatted or processed versions of this manual, if unaccompanied by
22.\" the source, must acknowledge the copyright and authors of this work.
4b72fb64 23.\" %%%LICENSE_END
1ae9f937 24.\"
5722c835 25.TH PTY 7 2015-07-23 "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.
40a1b471 51Pseudoterminals 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
60b3b93c
MK
59Data flow between master and slave is handled asynchronously,
60much like data flow with a physical terminal.
61Data written to the slave will be available at the master promptly,
62but may not be available immediately.
63Similarly, there may be a small processing delay between
4b063769
N
64a write to the master, and the effect being visible at the slave.
65
b218b023
MK
66Historically, two pseudoterminal APIs have evolved: BSD and System V.
67SUSv1 standardized a pseudoterminal API based on the System V API,
c13182ef 68and this API should be employed in all new programs that use
b218b023 69pseudoterminals.
1ae9f937 70
d9bfdb9c 71Linux provides both BSD-style and (standardized) System V-style
b218b023
MK
72pseudoterminals.
73System V-style terminals are commonly called UNIX 98 pseudoterminals
1ae9f937 74on Linux systems.
b218b023 75Since kernel 2.6.4, BSD-style pseudoterminals are considered deprecated
c13182ef 76(they can be disabled when configuring the kernel);
b218b023 77UNIX 98 pseudoterminals should be used in new applications.
73d8cece 78.SS UNIX 98 pseudoterminals
b218b023 79An unused UNIX 98 pseudoterminal master is opened by calling
1ae9f937
MK
80.BR posix_openpt (3).
81(This function opens the master clone device,
c13182ef
MK
82.IR /dev/ptmx ;
83see
5872bd2f 84.BR pts (4).)
d9bfdb9c 85After performing any program-specific initializations,
c13182ef 86changing the ownership and permissions of the slave device using
1ae9f937 87.BR grantpt (3),
c13182ef 88and unlocking the slave using
1ae9f937
MK
89.BR unlockpt (3)),
90the corresponding slave device can be opened by passing
c13182ef 91the name returned by
1ae9f937
MK
92.BR ptsname (3)
93in a call to
94.BR open (2).
95
96The Linux kernel imposes a limit on the number of available
b218b023 97UNIX 98 pseudoterminals.
1ae9f937 98In kernels up to and including 2.6.3, this limit is configured
47433403
MK
99at kernel compilation time
100.RB ( CONFIG_UNIX98_PTYS ),
b218b023 101and the permitted number of pseudoterminals can be up to 2048,
1ae9f937 102with a default setting of 256.
c13182ef 103Since kernel 2.6.4, the limit is dynamically adjustable via
1ae9f937
MK
104.IR /proc/sys/kernel/pty/max ,
105and a corresponding file,
106.IR /proc/sys/kernel/pty/nr ,
b218b023 107indicates how many pseudoterminals are currently in use.
1ae9f937
MK
108For further details on these two files, see
109.BR proc (5).
73d8cece 110.SS BSD pseudoterminals
b218b023 111BSD-style pseudoterminals are provided as precreated pairs, with
c13182ef 112names of the form
1ae9f937
MK
113.I /dev/ptyXY
114(master) and
115.I /dev/ttyXY
116(slave),
117where X is a letter from the 16-character set [p-za-e],
118and Y is a letter from the 16-character set [0-9a-f].
008f1ecc 119(The precise range of letters in these two sets varies across UNIX
1ae9f937
MK
120implementations.)
121For example,
122.I /dev/ptyp1
123and
124.I /dev/ttyp1
b218b023
MK
125constitute a BSD pseudoterminal pair.
126A process finds an unused pseudoterminal pair by trying to
1ae9f937 127.BR open (2)
b218b023
MK
128each pseudoterminal master until an open succeeds.
129The corresponding pseudoterminal slave (substitute "tty"
1ae9f937 130for "pty" in the name of the master) can then be opened.
47297adb 131.SH FILES
c13182ef 132.I /dev/ptmx
008f1ecc 133(UNIX 98 master clone device)
1ae9f937
MK
134.br
135.I /dev/pts/*
008f1ecc 136(UNIX 98 slave devices)
1ae9f937 137.br
c13182ef 138.I /dev/pty[p-za-e][0-9a-f]
1ae9f937
MK
139(BSD master devices)
140.br
c13182ef 141.I /dev/tty[p-za-e][0-9a-f]
1ae9f937 142(BSD slave devices)
47297adb 143.SH NOTES
2b2581ee
MK
144A description of the
145.B TIOCPKT
146.BR ioctl (2),
147which controls packet mode operation, can be found in
148.BR tty_ioctl (4).
149
47433403
MK
150The BSD
151.BR ioctl (2)
152operations
153.BR TIOCSTOP ,
154.BR TIOCSTART ,
155.BR TIOCUCNTL ,
156and
157.BR TIOCREMOTE
158have not been implemented under Linux.
47297adb 159.SH SEE ALSO
1ae9f937
MK
160.BR select (2),
161.BR setsid (2),
162.BR forkpty (3),
163.BR openpty (3),
164.BR termios (3),
5872bd2f 165.BR pts (4),
1ae9f937
MK
166.BR tty (4),
167.BR tty_ioctl (4)