/dev/
(for example,
/dev/tty03
and
/dev/dty03
).
The
/dev/ttyXX
special file is used for dial-in modems and terminals.
When a user logs into
the system on one of these hardware terminal ports, the system has already
opened the associated device and prepared the line for normal interactive
use (see
getty(8)).
The
/dev/dtyXX
special file is a SunOS-compatible dial-out device. Unlike
the dial-in device, opening the dial-out device never blocks. If the
corresponding dial-in device is already opened (not blocked in the open waiting
for carrier), then the dial-out open will fail immediately; otherwise it will
succeed immediately. While the dial-out device is open, the dial-in device may
not be opened. If the dial-in open is blocking, it will wait until the dial-out
device is closed (and carrier is detected); otherwise it will fail immediately.
There is also a special case of a terminal file that connects not to a hardware terminal port, but to another program on the other side. These special terminal devices are called ptys (pseudo terminals) and provide the mechanism necessary to give users the same interface to the system when logging in over a network (using rlogin(1), or telnet(1) for example.) Even in these cases the details of how the terminal file was opened and set up is already handled by special software in the system. Thus, users do not normally need to worry about the details of how these lines are opened or used. Also, these lines are often used for dialing out of a system (through an out-calling modem), but again the system provides programs that hide the details of accessing these terminal special files (see tip(1)).
When an interactive user logs in, the system prepares the line to behave in a certain way (called a line discipline), the particular details of which is described in stty(1) at the command level, and in termios(4) at the programming level. A user may be concerned with changing settings associated with his particular login terminal and should refer to the preceding man pages for the common cases. The remainder of this man page is concerned with describing details of using and controlling terminal devices at a low level, such as that possibly required by a program wishing to provide features similar to those provided by the system.
termios
line discipline is associated with the file. This is the primary
line discipline that is used in most cases and provides the semantics
that users normally associate with a terminal. When the
termios
line discipline is in effect, the terminal file behaves and is
operated according to the rules described in
termios(4).
Please refer to that man page for a full description of the terminal
semantics.
The operations described here
generally represent features common
across all
line disciplines,
however some of these calls may not
make sense in conjunction with a line discipline other than
termios
,
and some may not be supported by the underlying
hardware (or lack thereof, as in the case of ptys).
TIOCSLINED char name[32]
and would be called on the terminal associated with
file descriptor zero by the following code fragment:
ioctl(0, TIOCSLINED, "termios");
TIOCSLINED
char
name[32]
name
.
TIOCGLINED
char
name[32]
name
.
TIOCSBRK
void
TIOCCBRK
void
TIOCSDTR
void
TIOCCDTR
void
TIOCGPGRP
int
*tpgrp
tpgrp
.
This is the underlying call that implements the
tcgetpgrp(3)
call.
TIOCSPGRP
int
*tpgrp
tpgrp
.
This is the underlying call that implements the
tcsetpgrp(3)
call.
TIOCGETA
struct
termios
*term
term
.
This is the underlying call that implements the
tcgetattr(3)
call.
TIOCSETA
struct
termios
*term
TCSANOW
option.
TIOCSETAW
struct
termios
*term
TCSADRAIN
option.
TIOCSETAF
struct
termios
*term
TCSAFLUSH
option.
TIOCOUTQ
int
*num
num
.
TIOCSTI
char
*cp
cp
.
TIOCNOTTY
void
/dev/tty
and calling
TIOCNOTTY
on that file descriptor.
The current system does not allocate a controlling terminal to
a process on an
open()
call: there is a specific ioctl called
TIOCSCTTY
to make a terminal the controlling
terminal.
In addition, a program can
fork()
and call the
setsid(
)
system call which will place the process into its own session - which
has the effect of disassociating it from the controlling terminal. This
is the new and preferred method for programs to lose their controlling
terminal.
TIOCSTOP
void
TIOCSTART
void
TIOCSCTTY
void
TIOCDRAIN
void
TIOCEXCL
void
TIOCNXCL
void
TIOCFLUSH
int
*what
what
contains the
FREAD
bit as defined in
<
sys/fcntl.h
>,
then all characters in the input queue are cleared. If it contains
the
FWRITE
bit, then all characters in the output queue are cleared. If the
value of the integer is zero, then it behaves as if both the
FREAD
and
FWRITE
bits were set (i.e. clears both queues).
TIOCGWINSZ
struct
winsize
*ws
ws
.
The window size structure contains the number of rows and columns (and pixels
if appropriate) of the devices attached to the terminal. It is set by user software
and is the means by which most full-screen oriented programs determine the
screen size. The
winsize
structure is defined in
<
sys/ioctl.h
>.
TIOCSWINSZ
struct
winsize
*ws
ws
(see above).
TIOCCONS
int
*on
on
points to a non-zero integer, redirect kernel console output (kernel printf's)
to this terminal.
If
on
points to a zero integer, redirect kernel console output back to the normal
console. This is usually used on workstations to redirect kernel messages
to a particular window.
TIOCMSET
int
*state
state
contains bits that correspond to modem state.
Following is a list of defined variables and the modem state they represent:
This call sets the terminal modem state to that represented by
state
.
Not all terminals may support this.
TIOCMGET
int
*state
state
.
TIOCMBIS
int
*state
state
represent modem state as described above, however the state is OR-ed
in with the current state.
TIOCMBIC
int
*state
state
represent modem state as described above, however each bit which is on
in
state
is cleared in the terminal.
TIOCSFLAGS
int
*state
state
contain bits that correspond to serial port state.
Following is a list of defined flag values and the serial port state they
represent:
CLOCAL
flag on open.
CRTSCTS
flag on open.
MDMBUF
flag on open.
This call sets the serial port state to that represented by
state
.
Not all serial ports may support this.
TIOCGFLAGS
int
*state
state
.
TIOCSETD
int
*ldisc
ldisc
.
The old list of available line disciplines are listed in
<
sys/ttycom.h
>
and are:
TIOCGETD
int
*ldisc
ldisc
.