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

NAME

6       pty - pseudo-terminal interfaces
7

DESCRIPTION

9       A pseudo-terminal is a pair of virtual character devices that provide a
10       bidirectional communication channel.  One end of the channel is  called
11       the  master;  the  other end is called the slave.  The slave end of the
12       pseudo-terminal provides an interface that behaves exactly like a clas‐
13       sical  terminal.  A process that expects to be connected to a terminal,
14       can open the slave end of a pseudo-terminal and then  be  driven  by  a
15       program  that  has  opened the master end.  Anything that is written on
16       the master end is provided to the process on the slave end as though it
17       was  input  typed  on  a  terminal.  For example, writing the interrupt
18       character (usually control-C) to  the  master  device  would  cause  an
19       interrupt  signal  (SIGINT)  to be generated for the foreground process
20       group that is connected to the slave.   Conversely,  anything  that  is
21       written  to  the  slave  end  of the pseudo-terminal can be read by the
22       process that is connected to the master end.  Pseudo-terminals are used
23       by applications such as network login services (ssh(1), rlogin(1), tel‐
24       net(1)), terminal emulators, script(1), screen(1), and expect(1).
25
26       Historically, two pseudo-terminal APIs have evolved: BSD and System  V.
27       SUSv1 standardized a pseudo-terminal API based on the System V API, and
28       this API should be employed in all new programs that use  pseudo-termi‐
29       nals.
30
31       Linux provides both BSD-style and (standardized) System V-style pseudo-
32       terminals.  System  V-style  terminals  are  commonly  called  Unix  98
33       pseudo-terminals  on  Linux  systems.   Since  kernel  2.6.4, BSD-style
34       pseudo-terminals are considered deprecated (they can be  disabled  when
35       configuring the kernel); Unix 98 pseudo-terminals should be used in new
36       applications.
37
38   Unix 98 pseudo-terminals
39       An  unused  Unix  98  pseudo-terminal  master  is  opened  by   calling
40       posix_openpt(3).    (This  function  opens  the  master  clone  device,
41       /dev/ptmx; see pts(4).)  After performing any program-specific initial‐
42       izations,  changing  the  ownership and permissions of the slave device
43       using grantpt(3), and unlocking the slave using unlockpt(3)), the  cor‐
44       responding  slave  device can be opened by passing the name returned by
45       ptsname(3) in a call to open(2).
46
47       The Linux kernel imposes a limit on the number  of  available  Unix  98
48       pseudo-terminals.   In kernels up to and including 2.6.3, this limit is
49       configured at kernel compilation  time  (CONFIG_UNIX98_PTYS),  and  the
50       permitted  number of pseudo-terminals can be up to 2048, with a default
51       setting  of  256.   Since  kernel  2.6.4,  the  limit  is   dynamically
52       adjustable  via  /proc/sys/kernel/pty/max,  and  a  corresponding file,
53       /proc/sys/kernel/pty/nr, indicates how many pseudo-terminals  are  cur‐
54       rently in use.  For further details on these two files, see proc(5).
55
56   BSD pseudo-terminals
57       BSD-style  pseudo-terminals  are  provided  as  pre-created pairs, with
58       names of the form /dev/ptyXY (master) and /dev/ttyXY (slave),  where  X
59       is  a letter from the 16-character set [p-za-e], and Y is a letter from
60       the 16-character set [0-9a-f].  (The precise range of letters in  these
61       two  sets varies across Unix implementations.)  For example, /dev/ptyp1
62       and /dev/ttyp1 constitute a BSD pseudo-terminal pair.  A process  finds
63       an  unused pseudo-terminal pair by trying to open(2) each pseudo-termi‐
64       nal master until an open succeeds.  The  corresponding  pseudo-terminal
65       slave  (substitute  "tty" for "pty" in the name of the master) can then
66       be opened.
67

FILES

69       /dev/ptmx (Unix 98 master clone device)
70       /dev/pts/* (Unix 98 slave devices)
71       /dev/pty[p-za-e][0-9a-f] (BSD master devices)
72       /dev/tty[p-za-e][0-9a-f] (BSD slave devices)
73

NOTES

75       A description of the TIOCPKT ioctl(2), which controls packet mode oper‐
76       ation, can be found in tty_ioctl(4).
77
78       The BSD ioctl(2) operations TIOCSTOP, TIOCSTART, TIOCUCNTL, and TIOCRE‐
79       MOTE have not been implemented under Linux.
80

SEE ALSO

82       select(2),  setsid(2),  forkpty(3),  openpty(3),  termios(3),   pts(4),
83       tty(4), tty_ioctl(4)
84

COLOPHON

86       This  page  is  part of release 3.22 of the Linux man-pages project.  A
87       description of the project, and information about reporting  bugs,  can
88       be found at http://www.kernel.org/doc/man-pages/.
89
90
91
92Linux                             2005-10-10                            PTY(7)
Impressum