Home

pty

PTY is an acronym that commonly refers to a pseudo-terminal in Unix-like operating systems. A pseudo-terminal is a pair of devices—a master and a slave—that together emulate the behavior of a physical terminal. The master side is controlled by a program, while the slave side is presented to another process as if it were a real terminal.

How it works: a program that needs terminal interaction allocates a PTY pair. On Linux and Unix,

Typical uses include terminal emulators (such as xterm, GNOME Terminal), remote login services (SSH), and terminal

In relation to traditional TTYs, a PTY pair creates a virtual TTY where the slave side exposes

this
is
typically
done
by
requesting
a
master
device
(for
example
via
posix_openpt)
and
then
granting
access
and
unlocking
the
corresponding
slave
with
grantpt
and
unlockpt,
followed
by
obtaining
the
slave’s
path
with
ptsname.
The
master
device
is
used
by
the
controlling
program
to
send
input
and
read
output,
while
the
slave
device
behaves
like
a
traditional
terminal
for
the
process
that
runs
on
it
(for
example
a
shell
or
text
editor).
Terminal
semantics
such
as
echoing,
line
discipline,
and
character
buffering
are
provided
by
the
system
for
the
slave
side.
multiplexers
(screen,
tmux)
that
require
programmatic
control
of
a
terminal
session.
PTYs
allow
automated
tools
to
interact
with
interactive
programs
by
simulating
a
user
at
a
terminal,
while
keeping
the
controlling
process
separate
from
the
program
that
runs
inside
the
terminal.
a
real
terminal
interface
to
a
process,
and
the
master
side
provides
the
control
channel
to
another
program.
Other
meanings
of
the
acronym
PTY
exist
in
different
domains,
but
in
computing
this
article
refers
to
pseudo-terminals.