termios(3C) termios(3C)
NAME
termios: tcgetattr, tcsetattr, tcsendbreak, tcdrain, tcflush, tcflow,
cfgetospeed, cfsetospeed, cfgetispeed, cfsetispeed, tcgetpgrp,
tcsetpgrp, tcgetsid - general terminal interface
SYNOPSIS
#include <termios.h>
int tcgetattr(int fildes, struct termios *termiosp);
int tcsetattr(int fildes, int optionalactions,
const struct termios *termiosp);
int tcsendbreak(int fildes, int duration);
int tcdrain(int fildes);
int tcflush(int fildes, int queueselector);
int tcflow(int fildes, int action);
speedt cfgetospeed(const struct termios *termiosp);
int cfsetospeed(const struct termios *termiosp, speedt speed);
speedt cfgetispeed(const struct termios *termiosp);
int cfsetispeed(const struct termios *termiosp, speedt speed);
#include <sys/types.h>
#include <unistd.h>
pidt tcgetpgrp(int fildes);
int tcsetpgrp(int fildes, pidt pgid);
pidt tcgetsid(int fildes);
DESCRIPTION
These functions describe a general terminal interface for controlling
asynchronous communications ports. A more detailed overview of the
terminal interface can be found in termio(7), which also describes an
ioctl(2) interface that provides the same functionality. However, the
function interface described here is the preferred user interface.
Many of the functions described here have a termiosp argument that is
a pointer to a termios structure. This structure contains the follow-
ing members:
Page 1 Reliant UNIX 5.44 Printed 11/98
termios(3C) termios(3C)
tcflagt ciflag; /* input modes */
tcflagt coflag; /* output modes */
tcflagt ccflag; /* control modes */
tcflagt clflag; /* local modes */
cct ccc[NCCS]; /* control chars */
These structure members are described in detail in termio(7).
Get and write terminal attributes
The tcgetattr() function gets the parameters associated with the
object referred by fildes and stores them in the termios structure
referenced by termiosp. This function may be invoked from a back-
ground process; however, the terminal attributes may be subsequently
changed by a foreground process.
The tcsetattr() function sets the parameters associated with the ter-
minal (unless support is required from the underlying hardware that is
not available) from the termios structure referenced by termiosp as
follows:
- If optionalactions is TCSANOW, the change occurs immediately.
- If optionalactions is TCSADRAIN, the change occurs after all out-
put written to fildes has been transmitted. This function should be
used when changing parameters that affect output.
- If optionalactions is TCSAFLUSH, the change occurs after all out-
put written to the object referred by fildes has been transmitted,
and all input that has been received but not read is discarded
before the change is made.
The symbolic constants for the values of optionalactions are defined
in <termios.h> [see termios(5)].
Line control
If the terminal is using asynchronous serial data transmission, the
tcsendbreak() function causes transmission of a continuous stream of
zero-valued bits for a specific duration. If duration is zero, it
causes transmission of zero-valued bits for at least 0.25 seconds, and
not more than 0.5 seconds. If duration is not zero, it behaves in a
way similar to tcdrain().
If the terminal is not using asynchronous serial data transmission,
the tcsendbreak() function sends data to generate a break condition or
returns without taking any action.
The tcdrain() function waits until all output written to the object
referred to by fildes has been transmitted.
Page 2 Reliant UNIX 5.44 Printed 11/98
termios(3C) termios(3C)
The tcflush() function discards data written to the object referred to
by fildes but not transmitted, or data received but not read, depend-
ing on the value of queueselector:
- If queueselector is TCIFLUSH, it flushes data received but not
read.
- If queueselector is TCOFLUSH, it flushes data written but not
transmitted.
- If queueselector is TCIOFLUSH, it flushes both data received but
not read, and data written but not transmitted.
The tcflow() function suspends transmission or reception of data on
the object referred to by fildes, depending on the value of action:
- If action is TCOOFF, it suspends output.
- If action is TCOON, it restarts suspended output.
- If action if TCIOFF, the system transmits a STOP character, which
causes the terminal device to stop transmitting data to the system.
- If action is TCION, the system transmits a START character, which
causes the terminal device to start transmitting data to the sys-
tem.
Get and set baud rate
The baud rate functions get and set the values of the input and output
baud rates in the termios structure. The effects on the terminal
device described below do not become effective until the tcsetattr()
function is successfully called.
The input and output baud rates are stored in the termios structure.
The values shown in the table are supported. The names in this table
are defined in <termios.h>.
___________________________________________
| Name Description Name Description|
|__________________________________________|
| B0 Hang up B600 600 baud |
| B50 50 baud B1200 1200 baud |
| B75 75 baud B1800 1800 baud |
| B110 110 baud B2400 2400 baud |
| B134 134.5 baud B4800 4800 baud |
| B150 150 baud B9600 9600 baud |
| B200 200 baud B19200 19200 baud |
| B300 300 baud B38400 38400 baud |
|__________________________________________|
Page 3 Reliant UNIX 5.44 Printed 11/98
termios(3C) termios(3C)
cfgetospeed() gets the output baud rate and stores it in the termios
structure pointed to by termiosp.
cfsetospeed() sets the output baud rate stored in the termios struc-
ture pointed to by termiosp to speed. The zero baud rate, B0, is used
to terminate the connection. If B0 is specified, the modem control
lines are no longer be asserted. Normally, this disconnects the line.
cfgetispeed() gets the input baud rate and stores it in the termios
structure pointed to by termiosp.
cfsetispeed()sets the input baud rate stored in the termios structure
pointed to by termiosp to speed. If the input baud rate is set to
zero, the input baud rate is specified by the value of the output baud
rate. Both cfsetispeed() and cfsetospeed() return a value of zero if
successful and -1 to indicate an error. Attempts to set unsupported
baud rates are ignored. This refers both to changes to baud rates not
supported by the hardware, and to changes setting the input and output
baud rates to different values if the hardware does not support this.
Get and set foreground process group ID for a terminal
tcsetpgrp() sets the foreground process group ID of the terminal
specified by fildes to pgid. The file associated with fildes must be
the controlling terminal of the calling process and the controlling
terminal must be currently associated with the session of the calling
process. pgid must match a process group ID of a process in the same
session as the calling process.
tcgetpgrp() returns the foreground process group ID of the terminal
specified by fildes. tcgetpgrp() is allowed from a process that is a
member of a background process group; however, the information may be
subsequently changed by a process that is a member of a foreground
process group.
Get session ID of a terminal
The tcgetsid() function obtains the process group ID of the session
for which the terminal specified by fildes is the controlling termi-
nal.
RESULT
On success, tcgetpgrp() returns the process group ID of the foreground
process group associated with the specified terminal. Otherwise, it
returns -1 and sets errno to indicate the error.
On success, tcgetsid() returns the session ID associated with the
specified terminal. Otherwise, it returns -1 and sets errno to indi-
cate the error.
Page 4 Reliant UNIX 5.44 Printed 11/98
termios(3C) termios(3C)
On success, cfgetispeed() returns a value of type speedt representing
the input baud rate. On success, cfgetospeed() likewise returns a
value of type speedt representing the output baud rate. Both func-
tions return the value from the termios structure without interpreta-
tion.
On success, all other functions return a value of 1. Otherwise, they
return -1 and set errno to indicate the error.
ERRORS
The following error code descriptions are function-specific. You will
find a general description in introprm2(2) or in errno(5).
All of the functions fail if one of more of the following are true:
EBADF The fildes argument is not a valid file descriptor.
ENOTTY The file associated with fildes is not a terminal.
The cfsetispeed() and the cfsetospeed() functions may fail if:
EINVAL The speed value is not a valid baud rate.
EINVAL The value of speed is outside the range of possible speed
values as specified in <termios.h>.
tcsetattr() also fails if the following is true:
EINVAL The optionalactions argument is not a proper value, or an
attempt was made to change an attribute represented in the
termios structure to an unsupported value.
EINTR tcsetattr() was interrupted by a signal.
tcsendbreak() also fails if the following is true:
EINVAL The device does not support the tcsendbreak() function.
tcdrain() also fails if one or more of the following are true:
EINTR A signal interrupted the tcdrain() function.
EINVAL The device does not support the tcdrain() function.
tcflush() also fails if the following is true:
EINVAL The device does not support the tcflush() function or the
queueselector argument is not a proper value.
Page 5 Reliant UNIX 5.44 Printed 11/98
termios(3C) termios(3C)
tcflow() also fails if the following is true:
EINVAL The device does not support the tcflow() function or the
action argument is not a proper value.
tcgetpgrp() also fails if the following is true:
ENOTTY The calling process does not have a controlling terminal, or
fildes does not refer to the controlling terminal.
tcsetpgrp() also fails if the following is true:
EINVAL pgid is not a valid process group ID.
ENOTTY The calling process does not have a controlling terminal, or
fildes does not refer to the controlling terminal, or the
controlling terminal is no longer associated with the ses-
sion of the calling process.
EPERM pgid does not match the process group of an existing process
in the same session as the calling process.
tcgetsid() also fails if the following is true:
EACCES The fildes argument is not associated with a controlling
terminal.
EBADF The fildes argument is not a valid file descriptor.
ENOTTY The file associated with fildes is not a terminal.
SEE ALSO
setpgid(2), setsid(2), unistd(4), termios(5), types(5), termio(7).
Page 6 Reliant UNIX 5.44 Printed 11/98