1pty(7) Miscellaneous Information Manual pty(7)
2
3
4
6 pty - pseudoterminal interfaces
7
9 A pseudoterminal (sometimes abbreviated "pty") is a pair of virtual
10 character devices that provide a bidirectional communication channel.
11 One end of the channel is called the master; the other end is called
12 the slave.
13
14 The slave end of the pseudoterminal provides an interface that behaves
15 exactly like a classical terminal. A process that expects to be con‐
16 nected to a terminal, can open the slave end of a pseudoterminal and
17 then be driven by a program that has opened the master end. Anything
18 that is written on the master end is provided to the process on the
19 slave end as though it was input typed on a terminal. For example,
20 writing the interrupt character (usually control-C) to the master de‐
21 vice would cause an interrupt signal (SIGINT) to be generated for the
22 foreground process group that is connected to the slave. Conversely,
23 anything that is written to the slave end of the pseudoterminal can be
24 read by the process that is connected to the master end.
25
26 Data flow between master and slave is handled asynchronously, much like
27 data flow with a physical terminal. Data written to the slave will be
28 available at the master promptly, but may not be available immediately.
29 Similarly, there may be a small processing delay between a write to the
30 master, and the effect being visible at the slave.
31
32 Historically, two pseudoterminal APIs have evolved: BSD and System V.
33 SUSv1 standardized a pseudoterminal API based on the System V API, and
34 this API should be employed in all new programs that use pseudotermi‐
35 nals.
36
37 Linux provides both BSD-style and (standardized) System V-style pseu‐
38 doterminals. System V-style terminals are commonly called UNIX 98
39 pseudoterminals on Linux systems.
40
41 Since Linux 2.6.4, BSD-style pseudoterminals are considered deprecated:
42 support can be disabled when building the kernel by disabling the CON‐
43 FIG_LEGACY_PTYS option. (Starting with Linux 2.6.30, that option is
44 disabled by default in the mainline kernel.) UNIX 98 pseudoterminals
45 should be used in new applications.
46
47 UNIX 98 pseudoterminals
48 An unused UNIX 98 pseudoterminal master is opened by calling
49 posix_openpt(3). (This function opens the master clone device,
50 /dev/ptmx; see pts(4).) After performing any program-specific initial‐
51 izations, changing the ownership and permissions of the slave device
52 using grantpt(3), and unlocking the slave using unlockpt(3)), the cor‐
53 responding slave device can be opened by passing the name returned by
54 ptsname(3) in a call to open(2).
55
56 The Linux kernel imposes a limit on the number of available UNIX 98
57 pseudoterminals. Up to and including Linux 2.6.3, this limit is con‐
58 figured at kernel compilation time (CONFIG_UNIX98_PTYS), and the per‐
59 mitted number of pseudoterminals can be up to 2048, with a default set‐
60 ting of 256.