This action might not be possible to undo. Are you sure you want to continue?
termios(3) - Linux man page
termios, tcgetattr, tcsetattr, tcsendbreak, tcdrain, tcflush, tcflow, cfmakeraw, cfgetospeed, cfgetispeed, cfsetispeed, cfsetospeed, cfsetspeed - get and set terminal attributes, line control, get and set baud rate
#include <termios.h> #include <unistd.h> int tcgetattr(int fd, struct termios *termios_p); int tcsetattr(int fd, int optional_actions, const struct termios *termios_p); int tcsendbreak(int fd, int duration); int tcdrain(int fd); int tcflush(int fd, int queue_selector); int tcflow(int fd, int action); void cfmakeraw(struct termios *termios_p); speed_t cfgetispeed(const struct termios *termios_p); speed_t cfgetospeed(const struct termios *termios_p); int cfsetispeed(struct termios *termios_p, speed_t speed); int cfsetospeed(struct termios *termios_p, speed_t speed);
The termios functions describe a general terminal interface that is provided to control asynchronous communications ports. Many of the functions described here have a termios_p argument that is a pointer to a termios structure. This structure contains at least the following members: tcflag_t tcflag_t tcflag_t tcflag_t cc_t c_iflag; c_oflag; c_cflag; c_lflag; c_cc[NCCS]; /* /* /* /* /* input modes */ output modes */ control modes */ local modes */ control chars */
The values that may be assigned to these fields are described below. In the case of the first four bit-mask fields, the definitions of some of the associated flags that may be set are only exposed if a specific feature test macro (see feature_test_macros(7)) is defined, as noted in brackets ("").
1 of 11 09/03/2011 12:37 PM
net/man/3/termios In the descriptions below.termios(3) . c_iflag flag constants: IGNBRK Ignore BREAK condition on input. IGNPAR Ignore framing errors and parity errors. ISTRIP Strip off eighth bit. IUCLC (not in POSIX) Map uppercase characters to lowercase on input. prefix a character with a parity error or framing error with \377 \0. If neither IGNPAR nor PARMRK is set.die.1-2001 as part of the XSI extension. read a character with a parity error or framing error as \0. then a BREAK causes the input and output queues to be flushed. except when PARMRK is set. IXON Enable XON/XOFF flow control on output. "not in POSIX" means that the value is not specified in POSIX. and if the terminal is the controlling terminal of a foreground process group. and "XSI" means that the value is specified in POSIX. IGNCR Ignore carriage return on input. PARMRK If IGNPAR is not set. BRKINT If IGNBRK is set. If it is not set but BRKINT is set. When neither IGNBRK nor BRKINT are set.Linux man page http://linux. a BREAK is ignored. a BREAK reads as a null byte ('\0'). it will cause a SIGINT to be sent to this foreground process group. ICRNL Translate carriage return to newline on input (unless IGNCR is set). 2 of 11 09/03/2011 12:37 PM . INPCK Enable input parity checking. INLCR Translate NL to CR on input.1-2001. in which case it reads as the sequence \377 \0 \0.
If unset. OCRNL Map CR to NL on output. Linux does not implement this bit. [requires _BSD_SOURCE or _SVID_SOURCE or _XOPEN_SOURCE] CRDLY 3 of 11 09/03/2011 12:37 PM .1-2001.1: OPOST Enable implementation-defined output processing.termios(3) . ONLCR (XSI) Map NL to CR-NL on output.) IXOFF Enable XON/XOFF flow control on input. OLCUC (not in POSIX) Map lowercase characters to uppercase on output.Linux man page http://linux. (The default is to allow just the START character to restart output. fill character is ASCII NUL ('\0'). OFDEL (not in POSIX) Fill character is ASCII DEL (0177). IMAXBEL (not in POSIX) Ring bell when input queue is full. unless marked otherwise.die.) NLDLY Newline delay mask.net/man/3/termios IXANY (XSI) Typing any character will restart stopped output. The remaining c_oflag flag constants are defined in POSIX. ONLRET Don't output CR. rather than using a timed delay. Values are NL0 and NL1. c_oflag flag constants defined in POSIX. and acts as if it is always set. (Not implemented on Linux. OFILL Send fill characters for a delay. ONOCR Don't output CR at column 0.
sg_ispeed and sg_ospeed. Values are BS0 or BS1. [requires _BSD_SOURCE or _SVID_SOURCE or _XOPEN_SOURCE] TABDLY Horizontal tab delay mask. [requires _BSD_SOURCE or _SVID_SOURCE] CBAUDEX (not in POSIX) Extra baud speed mask (1 bit). XTABS. that is.) [requires _BSD_SOURCE or _SVID_SOURCE or _XOPEN_SOURCE] VTDLY Vertical tab delay mask. rather than one. other systems use separate fields.net/man/3/termios Carriage return delay mask. CR1. expands tabs to spaces (with tab stops every eight columns). [requires _BSD_SOURCE or _SVID_SOURCE or _XOPEN_SOURCE] BSDLY Backspace delay mask.termios(3) . or CR3. [requires _BSD_SOURCE or _SVID_SOURCE or _XOPEN_SOURCE] c_cflag flag constants: CBAUD (not in POSIX) Baud speed mask (4+1 bits). TAB3 (or XTABS). or CS8.) CSIZE Character size mask. and provides cfgetispeed() and cfsetispeed() for getting at it. CS6. Values are CR0. CSTOPB Set two stop bits. TAB1. e. [requires _BSD_SOURCE or _SVID_SOURCE] (POSIX says that the baud speed is stored in the termios structure without specifying where precisely. A value of TAB3.g. (Has never been implemented. PARENB Enable parity generation on output and parity checking for input. TAB2.die. CR2. FFDLY Form feed delay mask. Values are TAB0. CREAD Enable receiver. PARODD 4 of 11 09/03/2011 12:37 PM . Values are CS5. Values are FF0 or FF1. Some systems use bits selected by CBAUD in c_cflag.Linux man page http://linux. included in CBAUD. CS7. Values are VT0 or VT1.
QUIT. uppercase characters are preceded by \ and lowercase characters are converted to uppercase.termios(3) .Linux man page http://linux.die. terminal is uppercase only. shifted left IBSHIFT bits. LOBLK (not in POSIX) Block output from a noncurrent shell layer. On output. KILL. SUSP. (Not implemented on Linux. CLOCAL Ignore modem control lines. and buffers by lines. the KILL character erases the current line. or DSUSP are received. STATUS. The values for the CIBAUD bits are the same as the values for the CBAUD bits.) CRTSCTS (not in POSIX) Enable RTS/CTS (hardware) flow control. ECHO Echo input characters.net/man/3/termios Parity for input and output is odd. REPRINT. EOL2. generate the corresponding signal. LNEXT. [requires _BSD_SOURCE or _SVID_SOURCE] c_lflag flag constants: ISIG When any of the characters INTR. For use by shl (shell layers). XCASE (not in POSIX. and WERASE. and WERASE erases the preceding word. ECHOK If ICANON is also set. [requires _BSD_SOURCE or _SVID_SOURCE] (Not implemented on Linux.) CIBAUD (not in POSIX) Mask for input speeds. This enables the special characters EOF. EOL. the ERASE character erases the preceding input character. not supported under Linux) If ICANON is also set. ERASE. except for characters preceded by \. ICANON Enable canonical mode. HUPCL Lower modem control lines after last process closes the device (hang up). Input is converted to lowercase. ECHOE If ICANON is also set. 5 of 11 09/03/2011 12:37 PM .
character 0x08 (BS) is echoed as ^H. and STOP are echoed as ^X. NL. START. This flag is toggled by typing the DISCARD character. and then not passed as input. WERASE to be interpreted. [requires _BSD_SOURCE or _SVID_SOURCE] NOFLSH Disable flushing the input and output queues when generating the SIGINT. [requires _BSD_SOURCE or _SVID_SOURCE] ECHOKE (not in POSIX) If ICANON is also set. characters are printed as they are being erased. For example. KILL is echoed by erasing each character on the line.termios(3) . SIGQUIT and SIGSUSP signals. [requires _BSD_SOURCE or _SVID_SOURCE] ECHOPRT (not in POSIX) If ICANON and IECHO are also set. as specified by ECHOE and ECHOPRT. PENDIN (not in POSIX. Recognized when ISIG is set. and for the IUCLC flag to be effective. (bash handles typeahead this way. echo the NL character even if ECHO is not set.Linux man page http://linux.die. Send a SIGINT signal. ASCII control signals other than TAB.) [requires _BSD_SOURCE or _SVID_SOURCE] IEXTEN Enable implementation-defined input processing.) FLUSHO (not in POSIX. 6 of 11 09/03/2011 12:37 PM .net/man/3/termios ECHONL If ICANON is also set. [requires _BSD_SOURCE or _SVID_SOURCE] DEFECHO (not in POSIX) Echo only when a process is reading. (Not implemented on Linux. DEL. not supported under Linux) Output is being flushed. The c_cc array defines the special control characters. LNEXT. Ctrl-C. ECHOCTL (not in POSIX) If ECHO is also set. rubout) Interrupt character. where X is the character with ASCII code 0x40 greater than the control signal. or also 0177. REPRINT. as well as ICANON must be enabled for the special characters EOL2. This flag. ETX. not supported under Linux) All characters in the input queue are reprinted when the next character is read. The symbolic indices (initial values) and meaning are: VINTR (003. TOSTOP Send the SIGTTOU signal to the process group of a background process which tries to write to its controlling terminal.
VEOF (004. If it is the first character of the line. NUL) Yet another end-of-line character. VSWTCH (not in POSIX. Recognized when ICANON is set. Send SIGQUIT signal. VKILL (025. Ctrl-\) Quit character. FS. and then not passed as input. VEOL2 (not in POSIX. NAK. and then not passed as input. Ctrl-H. and then not passed as input. DC3. which signifies end-of-file. or 010. Recognized when ICANON is set.Linux man page http://linux. More precisely: this character causes the pending tty buffer to be sent to the waiting user program without waiting for end-of-line. 0. and then not passed as input. Ctrl-U. VSUSP 7 of 11 09/03/2011 12:37 PM . DEL.die. and then not passed as input. Recognized when ICANON is set. Recognized when IXON is set. Stop output until Start character typed. rubout. EOT. the read() in the user program returns 0. VERASE (0177. 0. or also #) Erase character.) VSTART (021. Ctrl-D) End-of-file character. Recognized when ICANON is set. This erases the input since the last EOF or beginning-of-line. DC1. VMIN Minimum number of characters for non-canonical read. Recognized when ISIG is set. Ctrl-Q) Start character. VTIME Timeout in deciseconds for non-canonical read. BS. or Ctrl-X. or also @) Kill character. not supported under Linux. and then not passed as input. NUL) Switch character. Recognized when IXON is set. Recognized when ICANON is set. but does not erase past EOF or beginning-of-line. NUL) Additional end-of-line character. VSTOP (023. This erases the previous not-yeterased character.net/man/3/termios VQUIT (034. Restarts output stopped by the Stop character. Ctrl-S) Stop character. VEOL (0.termios(3) . (Used by shl only.
however. Recognized when ISIG is set. and then not passed as input. Ctrl-Y) Delayed suspend character: send SIGTSTP signal when the character is read by the user program.Linux man page http://linux. tcsetattr() sets the parameters associated with the terminal (unless support is required from the underlying hardware that is not available) from the termios structure referred to by termios_p. VLNEXT (not in POSIX. 017. and then not passed as input. not supported under Linux. This function may be invoked from a background process. and then not passed as input. Ctrl-W) Word erase. depriving it of a possible special meaning. Ctrl-O) Toggle: start/stop discarding pending output. and all input that has been received but not read will be discarded before the change is made. not supported under Linux. VREPRINT (not in POSIX. and then not passed as input. not supported under Linux. Ctrl-Z) Suspend character. This function should be used when changing parameters that affect output. status request: 024. Ctrl-R) Reprint unread characters. TCSADRAIN the change occurs after all output written to fd has been transmitted. Recognized when ICANON and IEXTEN are set. 031.die. 026. In non-canonical mode the special character meaning is replaced by the timeout meaning. Recognized when IEXTEN is set. the terminal attributes may be subsequently changed by a foreground process. If neither is set. VMIN may have the same value as VEOL. VEOF. VSTATUS (not in POSIX.termios(3) . Send SIGTSTP signal. ETB. except that VTIME. SUB. Ctrl-V) Literal next.net/man/3/termios (032. Ctrl-T). 022. TCSAFLUSH the change occurs after all output written to the object referred by fd has been transmitted. 027. or the timer times out. optional_actions specifies when the changes take effect: TCSANOW the change occurs immediately. VWERASE (not in POSIX. SYN. Recognized when ICANON and IEXTEN are set. the read will return immediately. TIME (indexed using VTIME) is a decisecond-valued timer. and then not passed as input. Quotes the next input character. and the system supports job control. and then not passed as input. tcgetattr() gets the parameters associated with the object referred by fd and stores them in the termios structure referenced by termios_p. a read will wait until at least one character has been received. 8 of 11 09/03/2011 12:37 PM . If only MIN is set. the read will not return before MIN characters have been received. EM. DC2. When both are set. VDSUSP (not in POSIX. respectively. and then return as soon as either MIN characters have been received or time TIME has passed since the last character was received. the read will return as soon as either at least one character has been received. Recognized when IEXTEN is set. Recognized when IEXTEN and ISIG are set. only giving the currently already available characters. If only TIME is set. MIN (indexed using VMIN) represents the minimum number of characters that should be received to satisfy the read. SI. VDISCARD (not in POSIX. DC4. These symbolic subscript values are all different.
which stops the terminal device from transmitting data to the system. it sends zero-valued bits for some implementation-defined length of time. TCION transmits a START character. Setting the speed to B0 instructs the modem to "hang up". The new values do not take effect until tcsetattr() is successfully called. it transmits zero-valued bits for at least 0. TCIOFLUSH flushes both data received but not read. or data received but not read. termios_p->c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN). If duration is not zero. tcdrain() waits until all output written to the object referred to by fd has been transmitted. TCOON restarts suspended output. and not more that 0. if the terminal is using asynchronous serial data transmission. termios_p->c_oflag &= ~OPOST. The input and output baud rates are stored in the termios structure. The default on open of a terminal file is that neither its input nor its output is suspended. and data written but not transmitted. depending on the value of queue_selector: TCIFLUSH flushes data received but not read. The actual bit rate corresponding to B38400 may be altered with setserial(8). If duration is zero. The baud rate functions are provided for getting and setting the values of the input and output baud rates in the termios structure. If the terminal is not using asynchronous serial data transmission. tcflow() suspends transmission or reception of data on the object referred to by fd. depending on the value of action: TCOOFF suspends output. TCOFLUSH flushes data written but not transmitted. cfmakeraw() sets the terminal attributes as follows: termios_p->c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON).die. 9 of 11 09/03/2011 12:37 PM .termios(3) . tcsendbreak() returns without taking any action.25 seconds.Linux man page http://linux.5 seconds. tcflush() discards data written to the object referred to by fd but not transmitted.net/man/3/termios tcsendbreak() transmits a continuous stream of zero-valued bits for a specific duration. which starts the terminal device transmitting data to the system. TCIOFF transmits a STOP character.
cfsetospeed() sets the output baud rate stored in the termios structure pointed to by termios_p to speed. is used to terminate the connection. which must be one of these constants: B0 B50 B75 B110 B134 B150 B200 B300 B600 B1200 B1800 B2400 B4800 B9600 B19200 B38400 B57600 B115200 B230400 The zero baud rate.1 (57600 and above). Thus. cfsetispeed() sets the input baud rate stored in the termios structure to speed. B0. the modem control lines shall no longer be asserted.net/man/3/termios termios_p->c_cflag &= ~(CSIZE | PARENB). Normally. which must be 10 of 11 09/03/2011 12:37 PM .die. CBAUDEX is a mask for the speeds beyond those defined in POSIX. If B0 is specified. this will disconnect the line. cfgetispeed() returns the input baud rate stored in the termios structure.Linux man page http://linux.termios(3) . B57600 & CBAUDEX is non-zero. cfgetospeed() returns the output baud rate stored in the termios structure pointed to by termios_p. termios_p->c_cflag |= CS8.
See Also stty(1). It takes the same arguments as cfsetispeed().. tcsendbreak() with non-zero duration behaves like tcdrain(). where N is at least 0.25. DU. termio(7). Tru64 send a break of duration milliseconds. feature_test_macros(7). AIX. perlopentut(1)..Linux man page http://linux.4BSD extension. pty(7). B9600 one finds the two constants EXTA.5. SunOS specifies a break of duration*N seconds. Many systems extend the list with much higher baud rates.die. EXTB ("External A" and "External B"). stdout(3). Linux. The effect of a non-zero duration with tcsendbreak() varies. Under Solaris and Unixware. when making multiple changes it may be necessary to follow this call with a further call to tcgetattr() to check that all changes have been performed successfully. cfgetospeed() returns the output baud rate stored in the termios structure.termios(3) . tty(4). FreeBSD and NetBSD and HP-UX and MacOS ignore the value of duration.net/man/3/termios specified as one of the Bnnn constants listed above for cfsetospeed(). exit(2). and sets both input and output speed. Note that tcsetattr() returns success if any of the requested changes could be successfully carried out. and not more than 0. setserial(8) Referenced By console_ioctl(4). -1 on failure and set errno to indicate the error. If the input baud rate is set to zero. Therefore. setpgid(2). tty_ioctl(4) 11 of 11 09/03/2011 12:37 PM . Return Value cfgetispeed() returns the input baud rate stored in the termios structure. cfsetspeed() is a 4. .. Notes Unix V7 and several later systems have a list of baud rates where after the fourteen values B0. All other functions return: 0 on success. the input baud rate will be equal to the output baud rate.
This action might not be possible to undo. Are you sure you want to continue?
We've moved you to where you read on your other device.
Get the full title to continue reading from where you left off, or restart the preview.