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