<s>
The	O
POSIX	B-Application
terminal	I-Application
interface	I-Application
is	O
the	O
generalized	O
abstraction	O
,	O
comprising	O
both	O
an	O
application	B-Application
programming	I-Application
interface	I-Application
for	O
programs	O
,	O
and	O
a	O
set	O
of	O
behavioural	O
expectations	O
for	O
users	O
of	O
a	O
terminal	B-Application
,	O
as	O
defined	O
by	O
the	O
POSIX	O
standard	O
and	O
the	O
Single	O
Unix	O
Specification	O
.	O
</s>
<s>
It	O
is	O
a	O
historical	O
development	O
from	O
the	O
terminal	B-Application
interfaces	O
of	O
BSD	B-Operating_System
version	O
4	O
and	O
Seventh	B-Operating_System
Edition	I-Operating_System
Unix	I-Operating_System
.	O
</s>
<s>
A	O
terminal	B-Application
is	O
a	O
character-oriented	O
device	O
,	O
comprising	O
streams	B-Operating_System
of	O
characters	O
received	O
from	O
and	O
sent	O
to	O
the	O
device	O
.	O
</s>
<s>
Although	O
the	O
streams	B-Operating_System
of	O
characters	O
are	O
structured	O
,	O
incorporating	O
control	O
characters	O
,	O
escape	O
codes	O
,	O
and	O
special	O
characters	O
,	O
the	O
I/O	O
protocol	O
is	O
not	O
structured	O
as	O
would	O
be	O
the	O
I/O	O
protocol	O
of	O
smart	O
,	O
or	O
intelligent	O
,	O
terminals	O
.	O
</s>
<s>
The	O
"	O
capabilities	O
"	O
of	O
a	O
terminal	B-Application
comprise	O
various	O
dumb	O
terminal	B-Application
features	O
that	O
are	O
above	O
and	O
beyond	O
what	O
is	O
available	O
from	O
a	O
pure	O
teletypewriter	O
,	O
which	O
programs	O
can	O
make	O
use	O
of	O
.	O
</s>
<s>
They	O
(	O
mainly	O
)	O
comprise	O
escape	O
codes	O
that	O
can	O
be	O
sent	O
to	O
or	O
received	O
from	O
the	O
terminal	B-Application
.	O
</s>
<s>
The	O
escape	O
codes	O
sent	O
to	O
the	O
terminal	B-Application
perform	O
various	O
functions	O
that	O
a	O
CRT	O
terminal	B-Application
(	O
or	O
software	O
terminal	B-Application
emulator	I-Application
)	O
is	O
capable	O
of	O
that	O
a	O
teletypewriter	O
is	O
not	O
,	O
such	O
as	O
moving	O
the	O
terminal	B-Application
's	O
cursor	O
to	O
positions	O
on	O
the	O
screen	O
,	O
clearing	O
and	O
scrolling	O
all	O
or	O
parts	O
of	O
the	O
screen	O
,	O
turning	O
on	O
and	O
off	O
attached	O
printer	O
devices	O
,	O
programmable	O
function	B-Application
keys	I-Application
,	O
changing	O
display	O
colours	O
and	O
attributes	O
(	O
such	O
as	O
reverse	B-General_Concept
video	I-General_Concept
)	O
,	O
and	O
setting	O
display	O
title	O
strings	O
.	O
</s>
<s>
The	O
escape	O
codes	O
received	O
from	O
the	O
terminal	B-Application
signify	O
things	O
such	O
as	O
function	B-Application
key	I-Application
,	O
arrow	B-Device
key	I-Device
,	O
and	O
other	O
special	O
keystrokes	O
(	O
home	B-Device
key	I-Device
,	O
end	B-Device
key	I-Device
,	O
help	B-Protocol
key	I-Protocol
,	O
PgUp	B-Device
key	I-Device
,	O
PgDn	B-Device
key	I-Device
,	O
insert	B-Device
key	I-Device
,	O
delete	B-Device
key	I-Device
,	O
and	O
so	O
forth	O
)	O
.	O
</s>
<s>
These	O
capabilities	O
are	O
encoded	O
in	O
databases	O
that	O
are	O
configured	O
by	O
a	O
system	O
administrator	O
and	O
accessed	O
from	O
programs	O
via	O
the	O
terminfo	B-Device
library	O
(	O
which	O
supersedes	O
the	O
older	O
termcap	B-Application
library	O
)	O
,	O
upon	O
which	O
in	O
turn	O
are	O
built	O
libraries	O
such	O
as	O
the	O
curses	B-Device
and	O
ncurses	B-Language
libraries	O
.	O
</s>
<s>
Application	O
programs	O
use	O
the	O
terminal	B-Application
capabilities	O
to	O
provide	O
textual	B-Application
user	I-Application
interfaces	I-Application
with	O
windows	O
,	O
dialogue	O
boxes	O
,	O
buttons	O
,	O
labels	O
,	O
input	O
fields	O
,	O
menus	O
,	O
and	O
so	O
forth	O
.	O
</s>
<s>
The	O
particular	O
set	O
of	O
capabilities	O
for	O
the	O
terminal	B-Application
that	O
a	O
(	O
terminal-aware	O
)	O
program	O
's	O
input	O
and	O
output	O
uses	O
is	O
obtained	O
from	O
the	O
database	O
rather	O
than	O
hardwired	O
into	O
programs	O
and	O
libraries	O
,	O
and	O
is	O
controlled	O
by	O
the	O
TERM	O
environment	O
variable	O
(	O
and	O
,	O
optionally	O
for	O
the	O
termcap	B-Application
and	O
terminfo	B-Device
libraries	O
,	O
the	O
TERMCAP	B-Application
and	O
TERMINFO	B-Device
environment	O
variables	O
,	O
respectively	O
)	O
.	O
</s>
<s>
This	O
variable	O
is	O
set	O
by	O
whatever	O
terminal	B-Application
monitor	O
program	O
spawns	O
the	O
programs	O
that	O
then	O
use	O
that	O
terminal	B-Application
for	O
its	O
input	O
and	O
output	O
,	O
or	O
sometimes	O
explicitly	O
.	O
</s>
<s>
The	O
getty	B-Device
program	O
(	O
or	O
equivalent	O
)	O
sets	O
the	O
TERM	O
environment	O
variable	O
according	O
to	O
a	O
system	O
database	O
(	O
variously	O
inittab	O
or	O
the	O
configuration	O
files	O
for	O
the	O
ttymon	O
or	O
launchd	B-Application
programs	O
)	O
defining	O
what	O
local	O
terminals	O
are	O
attached	O
to	O
what	O
serial	B-Protocol
ports	I-Protocol
and	O
what	O
terminal	B-Application
types	O
are	O
provided	O
by	O
local	O
virtual	B-Application
terminals	I-Application
or	O
the	O
local	O
system	O
console	O
.	O
</s>
<s>
A	O
dial-up	O
user	O
on	O
a	O
remote	O
terminal	B-Application
is	O
not	O
using	O
the	O
type	O
of	O
terminal	B-Application
that	O
the	O
system	O
commonly	O
expects	O
on	O
that	O
dial-up	O
line	O
,	O
and	O
so	O
manually	O
sets	O
the	O
TERM	O
environment	O
variable	O
immediately	O
after	O
login	O
to	O
the	O
correct	O
type	O
.	O
</s>
<s>
(	O
More	O
usually	O
,	O
the	O
terminal	B-Application
type	O
set	O
by	O
the	O
getty	B-Device
program	O
for	O
the	O
dial-up	O
line	O
,	O
that	O
the	O
system	O
administrator	O
has	O
determined	O
to	O
be	O
used	O
most	O
often	O
by	O
dial-up	O
users	O
with	O
remote	O
terminals	O
,	O
matches	O
the	O
one	O
used	O
by	O
the	O
dial-up	O
user	O
and	O
that	O
user	O
has	O
no	O
need	O
to	O
override	O
the	O
terminal	B-Application
type	O
.	O
)	O
</s>
<s>
The	O
SSH	B-Protocol
server	O
daemon	O
(	O
or	O
equivalent	O
such	O
as	O
the	O
rlogin	B-Application
daemon	O
)	O
sets	O
the	O
TERM	O
environment	O
variable	O
to	O
the	O
same	O
terminal	B-Application
type	O
as	O
the	O
SSH	B-Protocol
client	O
.	O
</s>
<s>
The	O
software	O
terminal	B-Application
emulator	I-Application
,	O
using	O
a	O
pseudoterminal	B-Protocol
,	O
sets	O
the	O
TERM	O
environment	O
variable	O
to	O
specify	O
the	O
type	O
of	O
terminal	B-Application
that	O
it	O
is	O
emulating	O
.	O
</s>
<s>
Emulated	O
terminals	O
often	O
do	O
not	O
exactly	O
match	O
real	O
terminal	B-Application
hardware	O
,	O
and	O
terminal	B-Application
emulators	I-Application
have	O
type	O
names	O
dedicated	O
for	O
their	O
use	O
.	O
</s>
<s>
The	O
xterm	B-Language
program	O
(	O
by	O
default	O
)	O
sets	O
xterm	B-Language
as	O
the	O
terminal	B-Application
type	O
,	O
for	O
example	O
.	O
</s>
<s>
The	O
GNU	B-Application
Screen	I-Application
program	O
sets	O
screen	O
as	O
the	O
terminal	B-Application
type	O
.	O
</s>
<s>
Terminals	O
provide	O
job	B-Operating_System
control	I-Operating_System
facilities	O
.	O
</s>
<s>
Interactively	O
,	O
the	O
user	O
at	O
the	O
terminal	B-Application
can	O
send	O
control	O
characters	O
that	O
suspend	O
the	O
currently	O
running	O
job	O
,	O
reverting	O
to	O
the	O
interactive	O
job	B-Operating_System
control	I-Operating_System
shell	O
that	O
spawned	O
the	O
job	O
,	O
and	O
can	O
run	O
commands	O
that	O
place	O
jobs	O
in	O
the	O
"	O
background	O
"	O
or	O
that	O
switch	O
another	O
,	O
background	O
,	O
job	O
into	O
the	O
foreground	O
(	O
unsuspending	O
it	O
if	O
necessary	O
)	O
.	O
</s>
<s>
Strictly	O
speaking	O
,	O
in	O
Unixes	O
a	O
terminal	B-Application
device	O
comprises	O
the	O
underlying	O
tty	O
device	O
driver	O
,	O
responsible	O
for	O
the	O
physical	O
control	O
of	O
the	O
device	O
hardware	O
via	O
I/O	O
instructions	O
and	O
handling	O
device	O
interrupt	O
requests	O
for	O
character	O
input	O
and	O
output	O
,	O
and	O
the	O
line	O
discipline	O
.	O
</s>
<s>
A	O
line	O
discipline	O
is	O
independent	O
of	O
the	O
actual	O
device	O
hardware	O
,	O
and	O
the	O
same	O
line	O
discipline	O
can	O
be	O
used	O
for	O
a	O
terminal	B-Application
concentrator	O
device	O
responsible	O
for	O
multiple	O
controlling	O
terminals	O
as	O
for	O
a	O
pseudoterminal	B-Protocol
.	O
</s>
<s>
In	O
fact	O
,	O
the	O
line	O
discipline	O
(	O
or	O
,	O
in	O
the	O
case	O
of	O
BSD	B-Operating_System
,	O
AIX	B-Application
,	O
and	O
other	O
systems	O
,	O
line	O
disciplines	O
)	O
are	O
the	O
same	O
across	O
all	O
terminal	B-Application
devices	O
.	O
</s>
<s>
It	O
is	O
the	O
line	O
discipline	O
that	O
is	O
responsible	O
for	O
local	B-Error_Name
echo	I-Error_Name
,	O
line	O
editing	O
,	O
processing	O
of	O
input	O
modes	O
,	O
processing	O
of	O
output	O
modes	O
,	O
and	O
character	O
mapping	O
.	O
</s>
<s>
In	O
Seventh	B-Operating_System
Edition	I-Operating_System
Unix	I-Operating_System
,	O
BSD	B-Operating_System
systems	O
and	O
derivatives	O
including	O
macOS	B-Application
,	O
and	O
Linux	B-Application
,	O
each	O
terminal	B-Application
device	O
can	O
be	O
switched	O
amongst	O
multiple	O
line	O
disciplines	O
.	O
</s>
<s>
In	O
the	O
ATT	O
STREAMS	B-Operating_System
system	O
,	O
line	O
disciplines	O
are	O
STREAMS	B-Operating_System
modules	O
that	O
may	O
be	O
pushed	O
onto	O
and	O
popped	O
off	O
a	O
STREAMS	B-Operating_System
I/O	O
stack	O
.	O
</s>
<s>
The	O
POSIX	B-Application
terminal	I-Application
interface	I-Application
is	O
derived	O
from	O
the	O
terminal	B-Application
interfaces	O
of	O
various	O
Unix	O
systems	O
.	O
</s>
<s>
The	O
terminal	B-Application
interface	O
provided	O
by	O
Unix	O
32V	O
and	O
Seventh	B-Operating_System
Edition	I-Operating_System
Unix	I-Operating_System
,	O
and	O
also	O
presented	O
by	O
BSD	B-Operating_System
version	O
4	O
as	O
the	O
old	O
terminal	B-Application
driver	O
,	O
was	O
a	O
simple	O
one	O
,	O
largely	O
geared	O
towards	O
teletypewriters	O
as	O
terminals	O
.	O
</s>
<s>
Input	O
was	O
entered	O
a	O
line	O
at	O
a	O
time	O
,	O
with	O
the	O
terminal	B-Application
driver	O
in	O
the	O
operating	O
system	O
(	O
and	O
not	O
the	O
terminals	O
themselves	O
)	O
providing	O
simple	O
line	O
editing	O
capabilities	O
.	O
</s>
<s>
Applications	O
reading	O
terminal	B-Application
input	O
would	O
receive	O
the	O
contents	O
of	O
the	O
buffer	O
only	O
when	O
the	O
key	O
was	O
pressed	O
on	O
the	O
terminal	B-Application
to	O
end	O
line	O
editing	O
.	O
</s>
<s>
The	O
key	O
sent	O
from	O
the	O
terminal	B-Application
to	O
the	O
system	O
would	O
erase	O
(	O
"	O
kill	O
"	O
)	O
the	O
entire	O
current	O
contents	O
of	O
the	O
editing	O
buffer	O
,	O
and	O
would	O
be	O
normally	O
displayed	O
as	O
an	O
''	O
symbol	O
followed	O
by	O
a	O
newline	O
sequence	O
to	O
move	O
the	O
print	O
position	O
to	O
a	O
fresh	O
blank	O
line	O
.	O
</s>
<s>
The	O
key	O
sent	O
from	O
the	O
terminal	B-Application
to	O
the	O
system	O
would	O
erase	O
the	O
last	O
character	O
from	O
the	O
end	O
of	O
the	O
editing	O
buffer	O
,	O
and	O
would	O
be	O
normally	O
displayed	O
as	O
an	O
''	O
symbol	O
,	O
which	O
users	O
would	O
have	O
to	O
recognize	O
as	O
denoting	O
a	O
"	O
rubout	O
"	O
of	O
the	O
preceding	O
character	O
(	O
teletypewriters	O
not	O
being	O
physically	O
capable	O
of	O
erasing	O
characters	O
once	O
they	O
have	O
been	O
printed	O
on	O
the	O
paper	O
)	O
.	O
</s>
<s>
From	O
a	O
programming	O
point	O
of	O
view	O
,	O
a	O
terminal	B-Application
device	O
had	O
transmit	O
and	O
receive	O
baud	O
rates	O
,	O
"	O
erase	O
"	O
and	O
"	O
kill	O
"	O
characters	O
(	O
that	O
performed	O
line	O
editing	O
,	O
as	O
explained	O
)	O
,	O
"	O
interrupt	O
"	O
and	O
"	O
quit	O
"	O
characters	O
(	O
generating	O
signals	O
to	O
all	O
of	O
the	O
processes	O
for	O
which	O
the	O
terminal	B-Application
was	O
a	O
controlling	O
terminal	B-Application
)	O
,	O
"	O
start	O
"	O
and	O
"	O
stop	O
"	O
characters	O
(	O
used	O
for	O
modem	B-Application
flow	O
control	O
)	O
,	O
an	O
"	O
end	O
of	O
file	O
"	O
character	O
(	O
acting	O
like	O
a	O
carriage	O
return	O
except	O
discarded	O
from	O
the	O
buffer	O
by	O
the	O
read( )	O
system	O
call	O
and	O
therefore	O
potentially	O
causing	O
a	O
zero-length	O
result	O
to	O
be	O
returned	O
)	O
and	O
various	O
basic	O
mode	O
flags	O
determining	O
whether	O
local	B-Error_Name
echo	I-Error_Name
was	O
emulated	O
by	O
the	O
kernel	O
's	O
terminal	B-Application
driver	O
,	O
whether	O
modem	B-Application
flow	O
control	O
was	O
enabled	O
,	O
the	O
lengths	O
of	O
various	O
output	O
delays	O
,	O
mapping	O
for	O
the	O
carriage	O
return	O
character	O
,	O
and	O
the	O
three	O
input	O
modes	O
.	O
</s>
<s>
Applications	O
programs	O
reading	O
from	O
the	O
terminal	B-Application
receive	O
entire	O
lines	O
,	O
after	O
line	O
editing	O
has	O
been	O
completed	O
by	O
the	O
user	O
pressing	O
return	O
.	O
</s>
<s>
Applications	O
programs	O
reading	O
from	O
the	O
terminal	B-Application
receive	O
characters	O
immediately	O
,	O
as	O
soon	O
as	O
they	O
are	O
available	O
in	O
the	O
input	B-General_Concept
queue	I-General_Concept
to	O
be	O
read	O
.	O
</s>
<s>
However	O
,	O
the	O
"	O
interrupt	O
"	O
and	O
"	O
quit	O
"	O
control	O
characters	O
,	O
as	O
well	O
as	O
modem	B-Application
flow	O
control	O
characters	O
,	O
are	O
still	O
handled	O
specially	O
and	O
stripped	O
from	O
the	O
input	O
stream	O
.	O
</s>
<s>
Applications	O
programs	O
reading	O
from	O
the	O
terminal	B-Application
receive	O
characters	O
immediately	O
,	O
and	O
receive	O
the	O
entire	O
character	O
stream	O
unaltered	O
,	O
just	O
as	O
it	O
came	O
from	O
the	O
terminal	B-Application
device	O
itself	O
.	O
</s>
<s>
The	O
programmatic	O
interface	O
for	O
querying	O
and	O
modifying	O
all	O
of	O
these	O
modes	O
and	O
control	O
characters	O
was	O
the	O
ioctl( )	O
system	O
call	O
.	O
</s>
<s>
Although	O
the	O
"	O
erase	O
"	O
and	O
"	O
kill	O
"	O
characters	O
were	O
modifiable	O
from	O
their	O
defaults	O
of	O
and	O
,	O
for	O
many	O
years	O
they	O
were	O
the	O
pre-set	O
defaults	O
in	O
the	O
terminal	B-Application
device	O
drivers	O
,	O
and	O
on	O
many	O
Unix	O
systems	O
,	O
which	O
only	O
altered	O
terminal	B-Application
device	O
settings	O
as	O
part	O
of	O
the	O
login	O
process	B-Operating_System
,	O
in	O
system	O
login	O
scripts	O
that	O
ran	O
after	O
the	O
user	O
had	O
entered	O
username	O
and	O
password	O
,	O
any	O
mistakes	O
at	O
the	O
login	O
and	O
password	O
prompts	O
had	O
to	O
be	O
corrected	O
using	O
the	O
historical	O
editing	O
key	O
characters	O
inherited	O
from	O
teletypewriter	O
terminals	O
.	O
</s>
<s>
With	O
the	O
BSD	B-Operating_System
Unixes	I-Operating_System
came	O
job	B-Operating_System
control	I-Operating_System
,	O
and	O
a	O
new	O
terminal	B-Application
driver	O
with	O
extended	O
capabilities	O
.	O
</s>
<s>
The	O
"	O
suspend	O
"	O
and	O
"	O
delayed	O
suspend	O
"	O
characters	O
(	O
by	O
default	O
and	O
ASCII	O
SUB	O
and	O
EM	O
)	O
caused	O
the	O
generation	O
of	O
a	O
new	O
SIGTSTP	B-General_Concept
signal	B-General_Concept
to	O
processes	O
in	O
the	O
terminal	B-Application
's	O
controlling	O
process	B-Operating_System
group	O
.	O
</s>
<s>
The	O
"	O
word	O
erase	O
"	O
,	O
"	O
literal	O
next	O
"	O
,	O
and	O
"	O
reprint	O
"	O
characters	O
(	O
by	O
default	O
,	O
,	O
and	O
ASCII	O
ETB	B-Protocol
,	O
SYN	O
,	O
and	O
DC2	O
)	O
performed	O
additional	O
line	O
editing	O
functions	O
.	O
</s>
<s>
"	O
literal	O
next	O
"	O
allowed	O
any	O
special	O
character	O
to	O
be	O
entered	O
into	O
the	O
line	O
editing	O
buffer	O
(	O
a	O
function	O
available	O
,	O
somewhat	O
inconveniently	O
,	O
in	O
Seventh	B-Operating_System
Edition	I-Operating_System
Unix	I-Operating_System
via	O
the	O
backslash	O
character	O
)	O
.	O
</s>
<s>
"	O
reprint	O
"	O
caused	O
the	O
line	O
discipline	O
to	O
reprint	O
the	O
current	O
contents	O
of	O
the	O
line	O
editing	O
buffer	O
on	O
a	O
new	O
line	O
(	O
useful	O
for	O
when	O
another	O
,	O
background	O
,	O
process	B-Operating_System
had	O
generated	O
output	O
that	O
had	O
intermingled	O
with	O
line	O
editing	O
)	O
.	O
</s>
<s>
The	O
programmatic	O
interface	O
for	O
querying	O
and	O
modifying	O
all	O
of	O
these	O
extra	O
modes	O
and	O
control	O
characters	O
was	O
still	O
the	O
ioctl( )	O
system	O
call	O
,	O
which	O
its	O
creators	O
described	O
as	O
a	O
"	O
rather	O
cluttered	O
interface	O
"	O
.	O
</s>
<s>
All	O
of	O
the	O
original	O
Seventh	B-Operating_System
Edition	I-Operating_System
Unix	I-Operating_System
functionality	O
was	O
retained	O
,	O
and	O
the	O
new	O
functionality	O
was	O
added	O
via	O
additional	O
ioctl( )	O
operation	O
codes	O
,	O
resulting	O
in	O
a	O
programmatic	O
interface	O
that	O
had	O
clearly	O
grown	O
,	O
and	O
that	O
presented	O
some	O
duplication	O
of	O
functionality	O
.	O
</s>
<s>
System	B-Operating_System
III	I-Operating_System
introduced	O
a	O
new	O
programming	B-Application
interface	I-Application
that	O
combined	O
Seventh	O
Edition	O
's	O
separate	O
ioctl( )	O
operations	O
to	O
get	O
and	O
set	O
flags	O
and	O
to	O
get	O
and	O
set	O
control	O
characters	O
into	O
calls	O
that	O
used	O
a	O
termio	O
structure	O
to	O
hold	O
both	O
flags	O
and	O
control	O
characters	O
and	O
that	O
could	O
get	O
them	O
in	O
a	O
single	O
operation	O
and	O
set	O
them	O
in	O
another	O
single	O
operation	O
.	O
</s>
<s>
It	O
also	O
split	O
some	O
of	O
the	O
flags	O
from	O
the	O
Seventh	O
Edition	O
interface	O
into	O
multiple	O
separate	O
flags	O
,	O
and	O
added	O
some	O
additional	O
capabilities	O
,	O
although	O
it	O
did	O
not	O
support	O
job	B-Operating_System
control	I-Operating_System
or	O
the	O
cooked-mode	O
enhancements	O
of	O
4BSD	O
.	O
</s>
<s>
The	O
recognition	O
of	O
signal-generating	O
characters	O
is	O
independent	O
of	O
input	O
mode	O
,	O
and	O
there	O
are	O
only	O
the	O
two	O
input	O
modes	O
:	O
canonical	O
and	O
non-canonical	O
.	O
</s>
<s>
(	O
This	O
allows	O
a	O
terminal	B-Application
input	O
mode	O
not	O
present	O
in	O
Seventh	O
Edition	O
and	O
BSD	B-Operating_System
:	O
canonical	O
mode	O
with	O
signal	B-General_Concept
generation	O
disabled	O
.	O
)	O
</s>
<s>
System	B-Operating_System
III	I-Operating_System
's	O
successors	O
,	O
including	O
System	B-Operating_System
V	I-Operating_System
,	O
used	O
the	O
same	O
interface	O
.	O
</s>
<s>
One	O
of	O
the	O
major	O
problems	O
that	O
the	O
POSIX	O
standard	O
addressed	O
with	O
its	O
definition	O
of	O
a	O
general	O
terminal	B-Application
interface	O
was	O
the	O
plethora	O
of	O
programmatic	O
interfaces	O
.	O
</s>
<s>
Although	O
by	O
the	O
time	O
of	O
the	O
standard	O
the	O
behaviour	O
of	O
terminals	O
was	O
fairly	O
uniform	O
from	O
system	O
to	O
system	O
,	O
most	O
Unixes	O
having	O
adopted	O
the	O
notions	O
of	O
line	O
disciplines	O
and	O
the	O
BSD	B-Operating_System
job	B-Operating_System
control	I-Operating_System
capabilities	O
,	O
the	O
programmatic	O
interface	O
to	O
terminals	O
via	O
the	O
ioctl( )	O
system	O
call	O
was	O
a	O
mess	O
.	O
</s>
<s>
Different	O
Unixes	O
supplied	O
different	O
ioctl( )	O
operations	O
,	O
with	O
different	O
(	O
symbolic	O
)	O
names	O
,	O
and	O
different	O
flags	O
.	O
</s>
<s>
The	O
POSIX	O
standard	O
replaces	O
the	O
ioctl( )	O
system	O
entirely	O
,	O
with	O
a	O
set	O
of	O
library	O
functions	O
(	O
which	O
,	O
of	O
course	O
,	O
may	O
be	O
implemented	O
under	O
the	O
covers	O
via	O
platform-specific	O
ioctl( )	O
operations	O
)	O
with	O
standardized	O
names	O
and	O
parameters	O
.	O
</s>
<s>
The	O
termio	O
data	O
structure	O
of	O
System	B-Operating_System
V	I-Operating_System
Unix	I-Operating_System
was	O
used	O
as	O
a	O
template	O
for	O
the	O
POSIX	O
termios	O
data	O
structure	O
,	O
whose	O
fields	O
were	O
largely	O
unchanged	O
except	O
that	O
they	O
now	O
used	O
alias	O
data	O
types	O
for	O
specifying	O
the	O
fields	O
,	O
allowing	O
them	O
to	O
be	O
easily	O
ported	O
across	O
multiple	O
processor	O
architectures	O
by	O
implementors	O
,	O
rather	O
than	O
explicitly	O
requiring	O
the	O
unsigned	O
short	O
and	O
char	O
data	O
types	O
of	O
the	O
C	O
and	O
C++	O
programming	O
languages	O
(	O
which	O
might	O
be	O
inconvenient	O
sizes	O
on	O
some	O
processor	O
architectures	O
)	O
.	O
</s>
<s>
POSIX	O
also	O
introduced	O
support	O
for	O
job	B-Operating_System
control	I-Operating_System
,	O
with	O
the	O
termios	O
structure	O
containing	O
suspend	O
and	O
delayed-suspend	O
characters	O
in	O
addition	O
to	O
the	O
control	O
characters	O
supported	O
by	O
System	B-Operating_System
III	I-Operating_System
and	O
System	B-Operating_System
V	I-Operating_System
.	O
It	O
did	O
not	O
add	O
any	O
of	O
the	O
cooked-mode	O
extensions	O
from	O
BSD	B-Operating_System
,	O
although	O
SunOS	B-Operating_System
4.x	O
,	O
System	B-Operating_System
V	I-Operating_System
Release	O
4	O
,	O
Solaris	B-Application
,	O
HP-UX	B-Application
,	O
AIX	B-Application
,	O
newer	O
BSDs	B-Operating_System
,	O
macOS	B-Application
,	O
and	O
Linux	B-Application
have	O
implemented	O
them	O
as	O
extensions	O
to	O
termios	O
.	O
</s>
<s>
Each	O
process	B-Operating_System
in	O
the	O
system	O
has	O
either	O
a	O
single	O
controlling	O
terminal	B-Application
,	O
or	O
no	O
controlling	O
terminal	B-Application
at	O
all	O
.	O
</s>
<s>
A	O
process	B-Operating_System
inherits	O
its	O
controlling	O
terminal	B-Application
from	O
its	O
parent	O
,	O
and	O
the	O
only	O
operations	O
upon	O
a	O
process	B-Operating_System
are	O
acquiring	O
a	O
controlling	O
terminal	B-Application
,	O
by	O
a	O
process	B-Operating_System
that	O
has	O
no	O
controlling	O
terminal	B-Application
,	O
and	O
relinquishing	O
it	O
,	O
by	O
a	O
process	B-Operating_System
that	O
has	O
a	O
controlling	O
terminal	B-Application
.	O
</s>
<s>
No	O
portable	O
way	O
of	O
acquiring	O
a	O
controlling	O
terminal	B-Application
is	O
defined	O
,	O
the	O
method	O
being	O
implementation	O
defined	O
.	O
</s>
<s>
The	O
standard	O
defines	O
the	O
O_NOCTTY	O
flag	O
for	O
the	O
open( )	O
system	O
call	O
,	O
which	O
is	O
the	O
way	O
of	O
preventing	O
what	O
is	O
otherwise	O
the	O
conventional	O
way	O
of	O
acquiring	O
a	O
controlling	O
terminal	B-Application
(	O
a	O
process	B-Operating_System
with	O
no	O
controlling	O
terminal	B-Application
open( )	O
s	O
a	O
terminal	B-Application
device	O
file	O
that	O
is	O
n't	O
already	O
the	O
controlling	O
terminal	B-Application
for	O
some	O
other	O
process	B-Operating_System
,	O
without	O
specifying	O
the	O
O_NOCTTY	O
flag	O
)	O
but	O
leaves	O
its	O
conventional	O
semantics	O
optional	O
.	O
</s>
<s>
Each	O
process	B-Operating_System
also	O
is	O
a	O
member	O
of	O
a	O
process	B-Operating_System
group	O
.	O
</s>
<s>
Each	O
terminal	B-Application
device	O
records	O
a	O
process	B-Operating_System
group	O
that	O
is	O
termed	O
its	O
foreground	O
process	B-Operating_System
group	O
.	O
</s>
<s>
The	O
process	B-Operating_System
groups	O
control	O
terminal	B-Application
access	O
and	O
signal	B-General_Concept
delivery	O
.	O
</s>
<s>
Signals	O
generated	O
at	O
the	O
terminal	B-Application
are	O
sent	O
to	O
all	O
processes	O
that	O
are	O
members	O
of	O
the	O
terminal	B-Application
's	O
foreground	O
process	B-Operating_System
group	O
.	O
</s>
<s>
read( )	O
and	O
write( )	O
I/O	O
operations	O
on	O
a	O
terminal	B-Application
by	O
a	O
process	B-Operating_System
that	O
is	O
not	O
a	O
member	O
of	O
the	O
terminal	B-Application
's	O
foreground	O
process	B-Operating_System
group	O
will	O
and	O
may	O
optionally	O
(	O
respectively	O
)	O
cause	O
signals	O
(	O
SIGTTIN	B-General_Concept
and	O
SIGTTOU	B-General_Concept
respectively	O
)	O
to	O
be	O
sent	O
to	O
the	O
invoking	O
process	B-Operating_System
.	O
</s>
<s>
Various	O
terminal-mode-altering	O
library	O
functions	O
have	O
the	O
same	O
behaviour	O
as	O
write( )	O
,	O
except	O
that	O
they	O
always	O
generate	O
the	O
signals	O
,	O
even	O
if	O
that	O
functionality	O
is	O
turned	O
off	O
for	O
write( )	O
itself	O
.	O
</s>
<s>
The	O
data	O
structure	O
used	O
by	O
all	O
of	O
the	O
terminal	B-Application
library	O
calls	O
is	O
the	O
termios	O
structure	O
,	O
whose	O
C	O
and	O
C++	O
programming	O
language	O
definition	O
is	O
as	O
follows	O
:	O
</s>
<s>
The	O
data	O
type	O
aliases	O
tcflag_t	O
and	O
cc_t	O
,	O
as	O
well	O
as	O
the	O
symbolic	O
constant	O
NCCS	O
and	O
symbolic	O
constants	O
for	O
the	O
various	O
mode	O
flags	O
,	O
control	O
character	O
names	O
,	O
and	O
baud	O
rates	O
,	O
are	O
all	O
defined	O
in	O
a	O
standard	O
header	O
termios.h.	O
</s>
<s>
(	O
This	O
is	O
not	O
to	O
be	O
confused	O
with	O
the	O
similarly	O
named	O
header	O
termio.h	O
from	O
System	B-Operating_System
III	I-Operating_System
and	O
System	B-Operating_System
V	I-Operating_System
,	O
which	O
defines	O
a	O
similar	O
termio	O
structure	O
and	O
a	O
lot	O
of	O
similarly	O
named	O
symbolic	O
constants	O
.	O
</s>
<s>
This	O
interface	O
is	O
specific	O
to	O
System	B-Operating_System
III	I-Operating_System
and	O
System	B-Operating_System
V	I-Operating_System
,	O
and	O
code	O
that	O
uses	O
it	O
will	O
not	O
necessarily	O
be	O
portable	O
to	O
other	O
systems	O
.	O
)	O
</s>
<s>
Input	O
processing	O
determines	O
the	O
behaviour	O
of	O
the	O
read( )	O
system	O
call	O
on	O
a	O
terminal	B-Application
device	O
and	O
the	O
line	O
editing	O
and	O
signal-generation	O
characteristics	O
of	O
the	O
line	O
discipline	O
.	O
</s>
<s>
Unlike	O
the	O
case	O
of	O
Seventh	B-Operating_System
Edition	I-Operating_System
Unix	I-Operating_System
and	O
BSD	B-Operating_System
version	O
4	O
,	O
and	O
like	O
the	O
case	O
of	O
System	B-Operating_System
III	I-Operating_System
and	O
System	B-Operating_System
V	I-Operating_System
,	O
line	O
editing	O
operates	O
in	O
one	O
of	O
just	O
two	O
modes	O
:	O
canonical	O
mode	O
and	O
non-canonical	O
mode	O
.	O
</s>
<s>
The	O
basic	O
difference	O
between	O
them	O
is	O
when	O
,	O
from	O
the	O
point	O
of	O
view	O
of	O
the	O
blocking/non	O
-blocking	O
requirements	O
of	O
the	O
read( )	O
system	O
call	O
(	O
specified	O
with	O
the	O
O_NONBLOCK	O
flag	O
on	O
the	O
file	B-Application
descriptor	I-Application
via	O
open( )	O
or	O
fcntl( )	O
)	O
,	O
data	O
"	O
are	O
available	O
for	O
reading	O
"	O
.	O
</s>
<s>
In	O
canonical	O
mode	O
,	O
data	O
are	O
accumulated	O
in	O
a	O
line	O
editing	O
buffer	O
,	O
and	O
do	O
not	O
become	O
"	O
available	O
for	O
reading	O
"	O
until	O
line	O
editing	O
has	O
been	O
terminated	O
by	O
the	O
user	O
(	O
at	O
the	O
terminal	B-Application
)	O
sending	O
a	O
line	O
delimiter	O
character	O
.	O
</s>
