<s>
devpts	B-Application
is	O
a	O
virtual	O
filesystem	O
directory	O
available	O
in	O
the	O
Linux	B-Operating_System
kernel	I-Operating_System
since	O
version	O
2.1.93	O
(	O
April	O
1998	O
)	O
.	O
</s>
<s>
It	O
is	O
normally	O
mounted	O
at	O
/dev/pts	O
and	O
contains	O
solely	O
devices	O
files	O
which	O
represent	O
slaves	O
to	O
the	O
multiplexing	O
master	O
located	O
at	O
/dev/ptmx	O
which	O
in	O
turn	O
is	O
used	O
to	O
implement	O
terminal	B-Application
emulators	I-Application
(	O
such	O
as	O
X11	O
xterm	B-Language
)	O
.	O
</s>
<s>
A	O
pseudoterminal	B-Protocol
(	O
"	O
pseudo	B-Protocol
TTY	I-Protocol
"	O
or	O
"	O
PTY	O
"	O
)	O
is	O
a	O
pair	O
of	O
pseudo-devices	B-Application
–	O
a	O
slave	O
and	O
a	O
master	O
–	O
that	O
provide	O
a	O
special	O
sort	O
of	O
communication	O
channel	O
.	O
</s>
<s>
The	O
slave	O
pseudo-device	B-Application
emulates	O
a	O
physical	O
computer	O
text	O
terminal	O
(	O
like	O
,	O
e.g.	O
</s>
<s>
the	O
DEC	B-Device
VT100	I-Device
)	O
it	O
can	O
read	O
and	O
write	O
text	O
as	O
though	O
it	O
was	O
such	O
a	O
physical	O
terminal	O
.	O
</s>
<s>
The	O
master	O
pseudo-device	B-Application
provides	O
the	O
means	O
by	O
which	O
a	O
program	O
providing	O
a	O
text-based	O
user	O
interface	O
acts	O
with	O
and	O
controls	O
its	O
slave	O
.	O
</s>
<s>
Widely	O
spread	O
programs	O
with	O
a	O
text-based	O
user	O
interface	O
are	O
terminal	B-Application
emulators	I-Application
(	O
e.g.	O
</s>
<s>
xterm	B-Language
,	O
gnome-terminal	B-Language
or	O
Konsole	B-Language
)	O
,	O
or	O
programs	O
using	O
SSH	B-Protocol
or	O
telnet	B-Protocol
.	O
</s>
<s>
Writing	O
to	O
the	O
master	O
is	O
exactly	O
like	O
typing	O
on	O
a	O
terminal	O
,	O
thus	O
the	O
master	O
pseudo-device	B-Application
acts	O
kind	O
of	O
like	O
the	O
person	O
sitting	O
in	O
front	O
of	O
the	O
physical	O
computer	O
text	O
terminal	O
.	O
</s>
<s>
A	O
pseudoterminal	B-Protocol
pair	O
is	O
similar	O
to	O
a	O
bidirectional	O
pipe	O
.	O
</s>
<s>
Like	O
pipes	O
,	O
pseudoterminals	B-Protocol
have	O
a	O
limited	O
capacity	O
.	O
</s>
<s>
On	O
Linux	B-Application
,	O
the	O
pseudoterminal	B-Protocol
capacity	O
is	O
about	O
4	O
KiB	O
in	O
each	O
direction	O
.	O
</s>
<s>
A	O
typical	O
Linux	O
kernel-based	O
operating	O
system	O
provides	O
many	O
PTYs	O
to	O
support	O
text-based	O
interfaces	O
as	O
provided	O
by	O
terminal	B-Application
emulators	I-Application
(	O
such	O
as	O
xterm	B-Language
or	O
gnome-terminal	B-Language
)	O
and	O
remote	O
access	O
interfaces	O
like	O
SSH	B-Protocol
.	O
</s>
<s>
The	O
creation	O
of	O
devpts	B-Application
resulted	O
from	O
the	O
wish	O
to	O
abandon	O
the	O
need	O
for	O
a	O
setuid	O
helper	O
program	O
,	O
e.g.	O
</s>
<s>
It	O
is	O
a	O
distinct	O
implementation	O
of	O
the	O
pseudoterminal	B-Protocol
idea	O
;	O
the	O
previous	O
implementation	O
provided	O
a	O
fixed	O
number	O
of	O
master/slave	O
pairs	O
which	O
had	O
permanent	O
device	O
nodes	O
,	O
for	O
example	O
the	O
master-slave	O
pair	O
/dev/ptyp63	O
and	O
/dev/ttyp63	O
,	O
cf	O
.	O
</s>
<s>
The	O
Linux	B-Application
Programming	O
Interface	O
chapter	O
62	O
"	O
Terminals	O
"	O
and	O
chapter	O
64	O
"	O
Pseudoterminals	B-Protocol
"	O
.	O
</s>
<s>
In	O
February	O
1998	O
,	O
Linux	B-Application
2.1.87	O
brought	O
support	O
for	O
the	O
/dev/ptmx	O
multiplexing	O
master	O
device	O
.	O
</s>
<s>
Opening	O
this	O
device	O
provides	O
access	O
to	O
an	O
otherwise	O
unused	O
pseudo	B-Protocol
TTY	I-Protocol
master	O
and	O
allows	O
the	O
matching	O
slave	O
to	O
be	O
identified	O
using	O
an	O
.	O
</s>
<s>
In	O
April	O
of	O
that	O
year	O
,	O
Linux	B-Application
2.1.93	O
added	O
a	O
new	O
virtual	O
filesystem	O
called	O
devpts	B-Application
that	O
is	O
normally	O
mounted	O
at	O
/dev/pts	O
.	O
</s>
<s>
To	O
facilitate	O
moving	O
the	O
terminal	B-Application
emulation	I-Application
into	O
userland	O
,	O
while	O
still	O
keeping	O
the	O
TTY	O
subsystem	O
(	O
session	O
management	O
and	O
line	O
discipline	O
)	O
intact	O
,	O
the	O
pseudoterminal	B-Protocol
was	O
invented	O
.	O
</s>
<s>
The	O
reason	O
why	O
the	O
line	O
discipline	O
is	O
inside	O
the	O
kernel	B-Operating_System
,	O
is	O
to	O
avoid	O
context	B-Operating_System
switches	I-Operating_System
at	O
the	O
reception	O
of	O
each	O
character	O
(	O
which	O
in	O
the	O
early	O
times	O
of	O
small	O
core	O
memories	O
,	O
would	O
imply	O
swap-outs	O
and	O
swap-ins	O
!	O
)	O
.	O
</s>
<s>
So	O
the	O
line	O
discipline	O
keeps	O
in	O
a	O
kernel	B-Operating_System
buffer	O
a	O
line	O
of	O
input	O
,	O
and	O
since	O
it	O
is	O
simple	O
enough	O
to	O
test	O
for	O
a	O
specific	O
byte	O
and	O
decrement	O
a	O
counter	O
to	O
implement	O
the	O
backspace	O
"	O
editing	O
"	O
(	O
and	O
a	O
few	O
other	O
simple	O
editing	O
functions	O
)	O
,	O
it	O
's	O
done	O
there	O
.	O
</s>
<s>
The	O
alternative	O
is	O
to	O
use	O
the	O
raw	O
mode	O
,	O
where	O
the	O
characters	O
are	O
forwarded	O
to	O
the	O
application	O
as	O
soon	O
as	O
they	O
're	O
received	O
,	O
which	O
is	O
needed	O
for	O
more	O
sophisticated	O
editors	O
,	O
like	O
the	O
(	O
at	O
the	O
time	O
)	O
famously	O
known	O
Emacs	B-Application
.	O
</s>
<s>
And	O
indeed	O
,	O
since	O
emacs	B-Application
had	O
to	O
use	O
this	O
raw	O
mode	O
,	O
which	O
implies	O
a	O
context	B-Operating_System
switch	I-Operating_System
at	O
the	O
reception	O
of	O
each	O
character	O
typed	O
,	O
it	O
was	O
constantly	O
swapping	O
when	O
the	O
computers	O
had	O
n't	O
enough	O
memory	O
to	O
keep	O
emacs	B-Application
and	O
all	O
the	O
other	O
programs	O
in	O
core	O
.	O
</s>
<s>
With	O
the	O
addition	O
of	O
pseudo	B-Protocol
terminals	I-Protocol
(	O
PTYs	O
)	O
,	O
the	O
TTY	O
code	O
has	O
also	O
become	O
a	O
sort	O
of	O
interprocess	O
communication	O
mechanism	O
,	O
with	O
all	O
of	O
the	O
TTY	O
semantics	O
preserved	O
.	O
</s>
