1PTY(7)                     Linux Programmer's Manual                    PTY(7)
2
3
4

NAME

6       pty - pseudoterminal interfaces
7

DESCRIPTION

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.  The slave end of the pseudoterminal provides  an  interface
13       that behaves exactly like a classical terminal.  A process that expects
14       to be connected to a terminal, can open the slave end of a pseudotermi‐
15       nal  and  then  be  driven by a program that has opened the master end.
16       Anything that is written on the master end is provided to  the  process
17       on the slave end as though it was input typed on a terminal.  For exam‐
18       ple, writing the interrupt character (usually control-C) to the  master
19       device would cause an interrupt signal (SIGINT) to be generated for the
20       foreground process group that is connected to the  slave.   Conversely,
21       anything  that is written to the slave end of the pseudoterminal can be
22       read by the process that is connected to the master end.   Pseudotermi‐
23       nals  are  used by applications such as network login services (ssh(1),
24       rlogin(1), telnet(1)), terminal emulators such as xterm(1),  script(1),
25       screen(1), tmux(1), unbuffer(1), and expect(1).
26
27       Data flow between master and slave is handled asynchronously, much like
28       data flow with a physical terminal.  Data written to the slave will  be
29       available at the master promptly, but may not be available immediately.
30       Similarly, there may be a small processing delay between a write to the
31       master, and the effect being visible at the slave.
32
33       Historically,  two  pseudoterminal APIs have evolved: BSD and System V.
34       SUSv1 standardized a pseudoterminal API based on the System V API,  and
35       this  API  should be employed in all new programs that use pseudotermi‐
36       nals.
37
38       Linux provides both BSD-style and (standardized) System  V-style  pseu‐
39       doterminals.   System  V-style  terminals  are  commonly called UNIX 98
40       pseudoterminals on Linux systems.  Since kernel 2.6.4, BSD-style  pseu‐
41       doterminals  are  considered deprecated (they can be disabled when con‐
42       figuring the kernel); UNIX 98 pseudoterminals should  be  used  in  new
43       applications.
44
45   UNIX 98 pseudoterminals
46       An   unused   UNIX  98  pseudoterminal  master  is  opened  by  calling
47       posix_openpt(3).   (This  function  opens  the  master  clone   device,
48       /dev/ptmx; see pts(4).)  After performing any program-specific initial‐
49       izations, changing the ownership and permissions of  the  slave  device
50       using  grantpt(3), and unlocking the slave using unlockpt(3)), the cor‐
51       responding slave device can be opened by passing the name  returned  by
52       ptsname(3) in a call to open(2).
53
54       The  Linux  kernel  imposes  a limit on the number of available UNIX 98
55       pseudoterminals.  In kernels up to and including 2.6.3, this  limit  is
56       configured  at  kernel  compilation  time (CONFIG_UNIX98_PTYS), and the
57       permitted number of pseudoterminals can be up to 2048, with  a  default
58       setting   of  256.   Since  kernel  2.6.4,  the  limit  is  dynamically
59       adjustable via  /proc/sys/kernel/pty/max,  and  a  corresponding  file,
60       /proc/sys/kernel/pty/nr,  indicates  how  many pseudoterminals are cur‐
61       rently in use.  For further details on these two files, see proc(5).
62
63   BSD pseudoterminals
64       BSD-style pseudoterminals are provided as precreated pairs, with  names
65       of  the  form  /dev/ptyXY (master) and /dev/ttyXY (slave), where X is a
66       letter from the 16-character set [p-za-e], and Y is a letter  from  the
67       16-character  set [0-9a-f].  (The precise range of letters in these two
68       sets varies across UNIX implementations.)  For example, /dev/ptyp1  and
69       /dev/ttyp1  constitute  a  BSD pseudoterminal pair.  A process finds an
70       unused pseudoterminal pair by trying  to  open(2)  each  pseudoterminal
71       master  until an open succeeds.  The corresponding pseudoterminal slave
72       (substitute "tty" for "pty" in the name of  the  master)  can  then  be
73       opened.
74

FILES

76       /dev/ptmx
77              UNIX 98 master clone device
78
79       /dev/pts/*
80              UNIX 98 slave devices
81
82       /dev/pty[p-za-e][0-9a-f]
83              BSD master devices
84
85       /dev/tty[p-za-e][0-9a-f]
86              BSD slave devices
87

NOTES

89       A description of the TIOCPKT ioctl(2), which controls packet mode oper‐
90       ation, can be found in ioctl_tty(2).
91
92       The BSD ioctl(2) operations TIOCSTOP, TIOCSTART, TIOCUCNTL, and TIOCRE‐
93       MOTE have not been implemented under Linux.
94

SEE ALSO

96       ioctl_tty(2), select(2), setsid(2), forkpty(3), openpty(3), termios(3),
97       pts(4), tty(4)
98

COLOPHON

100       This page is part of release 4.16 of the Linux  man-pages  project.   A
101       description  of  the project, information about reporting bugs, and the
102       latest    version    of    this    page,    can     be     found     at
103       https://www.kernel.org/doc/man-pages/.
104
105
106
107Linux                             2017-09-15                            PTY(7)
Impressum