1 .\" Copyright (c) 1993 Michael Haardt (michael@moria.de)
2 .\" Fri Apr 2 11:32:09 MET DST 1993
3 .\" Copyright (c) 2006-2015, Michael Kerrisk <mtk.manpages@gmail.com>
5 .\" %%%LICENSE_START(GPLv2+_DOC_FULL)
6 .\" This is free documentation; you can redistribute it and/or
7 .\" modify it under the terms of the GNU General Public License as
8 .\" published by the Free Software Foundation; either version 2 of
9 .\" the License, or (at your option) any later version.
11 .\" The GNU General Public License's references to "object code"
12 .\" and "executables" are to be interpreted as the output of any
13 .\" document formatting or typesetting system, including
14 .\" intermediate and printed output.
16 .\" This manual is distributed in the hope that it will be useful,
17 .\" but WITHOUT ANY WARRANTY; without even the implied warranty of
18 .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 .\" GNU General Public License for more details.
21 .\" You should have received a copy of the GNU General Public
22 .\" License along with this manual; if not, see
23 .\" <http://www.gnu.org/licenses/>.
26 .\" Modified 1993-07-24 by Rik Faith <faith@cs.unc.edu>
27 .\" Modified 1995-02-25 by Jim Van Zandt <jrv@vanzandt.mv.com>
28 .\" Modified 1995-09-02 by Jim Van Zandt <jrv@vanzandt.mv.com>
29 .\" moved to man3, aeb, 950919
30 .\" Modified 2001-09-22 by Michael Kerrisk <mtk.manpages@gmail.com>
31 .\" Modified 2001-12-17, aeb
32 .\" Modified 2004-10-31, aeb
34 .\" Added .SS headers to give some structure to this page; and a
35 .\" small amount of reordering.
36 .\" Added a section on canonical and noncanonical mode.
37 .\" Enhanced the discussion of "raw" mode for cfmakeraw().
40 .TH TERMIOS 3 2021-03-22 "Linux" "Linux Programmer's Manual"
42 termios, tcgetattr, tcsetattr, tcsendbreak, tcdrain, tcflush, tcflow,
43 cfmakeraw, cfgetospeed, cfgetispeed, cfsetispeed, cfsetospeed, cfsetspeed \-
44 get and set terminal attributes, line control, get and set baud rate
47 .B #include <termios.h>
48 .B #include <unistd.h>
50 .BI "int tcgetattr(int " fd ", struct termios *" termios_p );
51 .BI "int tcsetattr(int " fd ", int " optional_actions ,
52 .BI " const struct termios *" termios_p );
54 .BI "int tcsendbreak(int " fd ", int " duration );
55 .BI "int tcdrain(int " fd );
56 .BI "int tcflush(int " fd ", int " queue_selector );
57 .BI "int tcflow(int " fd ", int " action );
59 .BI "void cfmakeraw(struct termios *" termios_p );
61 .BI "speed_t cfgetispeed(const struct termios *" termios_p );
62 .BI "speed_t cfgetospeed(const struct termios *" termios_p );
64 .BI "int cfsetispeed(struct termios *" termios_p ", speed_t " speed );
65 .BI "int cfsetospeed(struct termios *" termios_p ", speed_t " speed );
66 .BI "int cfsetspeed(struct termios *" termios_p ", speed_t " speed );
70 Feature Test Macro Requirements for glibc (see
71 .BR feature_test_macros (7)):
79 Glibc 2.19 and earlier:
83 The termios functions describe a general terminal interface that is
84 provided to control asynchronous communications ports.
85 .SS The termios structure
86 Many of the functions described here have a \fItermios_p\fP argument
87 that is a pointer to a \fItermios\fP structure.
88 This structure contains at least the following members:
92 tcflag_t c_iflag; /* input modes */
93 tcflag_t c_oflag; /* output modes */
94 tcflag_t c_cflag; /* control modes */
95 tcflag_t c_lflag; /* local modes */
96 cc_t c_cc[NCCS]; /* special characters */
100 The values that may be assigned to these fields are described below.
101 In the case of the first four bit-mask fields,
102 the definitions of some of the associated flags that may be set are
103 exposed only if a specific feature test macro (see
104 .BR feature_test_macros (7))
105 is defined, as noted in brackets ("[]").
107 In the descriptions below, "not in POSIX" means that the
108 value is not specified in POSIX.1-2001,
109 and "XSI" means that the value is specified in POSIX.1-2001
110 as part of the XSI extension.
112 \fIc_iflag\fP flag constants:
115 Ignore BREAK condition on input.
118 If \fBIGNBRK\fP is set, a BREAK is ignored.
120 but \fBBRKINT\fP is set, then a BREAK causes the input and output
121 queues to be flushed, and if the terminal is the controlling
122 terminal of a foreground process group, it will cause a
123 \fBSIGINT\fP to be sent to this foreground process group.
124 When neither \fBIGNBRK\fP nor \fBBRKINT\fP are set, a BREAK
125 reads as a null byte (\(aq\e0\(aq), except when \fBPARMRK\fP is set,
126 in which case it reads as the sequence \e377 \e0 \e0.
129 Ignore framing errors and parity errors.
132 If this bit is set, input bytes with parity or framing errors are
133 marked when passed to the program.
134 This bit is meaningful only when
135 \fBINPCK\fP is set and \fBIGNPAR\fP is not set.
136 The way erroneous bytes are marked is with two preceding bytes,
138 Thus, the program actually reads three bytes for one
139 erroneous byte received from the terminal.
140 If a valid byte has the value \e377,
141 and \fBISTRIP\fP (see below) is not set,
142 the program might confuse it with the prefix that marks a
144 Therefore, a valid byte \e377 is passed to the program as two
145 bytes, \e377 \e377, in this case.
147 If neither \fBIGNPAR\fP nor \fBPARMRK\fP
148 is set, read a character with a parity error or framing error
152 Enable input parity checking.
155 Strip off eighth bit.
158 Translate NL to CR on input.
161 Ignore carriage return on input.
164 Translate carriage return to newline on input (unless \fBIGNCR\fP is set).
167 (not in POSIX) Map uppercase characters to lowercase on input.
170 Enable XON/XOFF flow control on output.
173 (XSI) Typing any character will restart stopped output.
174 (The default is to allow just the START character to restart output.)
177 Enable XON/XOFF flow control on input.
180 (not in POSIX) Ring bell when input queue is full.
181 Linux does not implement this bit, and acts as if it is always set.
183 .BR IUTF8 " (since Linux 2.6.4)"
184 (not in POSIX) Input is UTF8;
185 this allows character-erase to be correctly performed in cooked mode.
191 Enable implementation-defined output processing.
194 (not in POSIX) Map lowercase characters to uppercase on output.
197 (XSI) Map NL to CR-NL on output.
200 Map CR to NL on output.
203 Don't output CR at column 0.
209 Send fill characters for a delay, rather than using a timed delay.
212 Fill character is ASCII DEL (0177).
213 If unset, fill character is ASCII NUL (\(aq\e0\(aq).
214 (Not implemented on Linux.)
218 Values are \fBNL0\fP and \fBNL1\fP.
227 Carriage return delay mask.
228 Values are \fBCR0\fP, \fBCR1\fP, \fBCR2\fP, or \fBCR3\fP.
237 Horizontal tab delay mask.
238 Values are \fBTAB0\fP, \fBTAB1\fP, \fBTAB2\fP, \fBTAB3\fP (or \fBXTABS\fP,
242 A value of TAB3, that is, XTABS, expands tabs to spaces
243 (with tab stops every eight columns).
252 Backspace delay mask.
253 Values are \fBBS0\fP or \fBBS1\fP.
254 (Has never been implemented.)
263 Vertical tab delay mask.
264 Values are \fBVT0\fP or \fBVT1\fP.
267 Form feed delay mask.
268 Values are \fBFF0\fP or \fBFF1\fP.
276 \fIc_cflag\fP flag constants:
279 (not in POSIX) Baud speed mask (4+1 bits).
286 (not in POSIX) Extra baud speed mask (1 bit), included in
293 (POSIX says that the baud speed is stored in the
295 structure without specifying where precisely, and provides
300 Some systems use bits selected by
304 other systems use separate fields, for example,
311 Values are \fBCS5\fP, \fBCS6\fP, \fBCS7\fP, or \fBCS8\fP.
314 Set two stop bits, rather than one.
320 Enable parity generation on output and parity checking for input.
323 If set, then parity for input and output is odd;
324 otherwise even parity is used.
327 Lower modem control lines after last process closes the device (hang up).
330 Ignore modem control lines.
333 (not in POSIX) Block output from a noncurrent shell layer.
334 For use by \fBshl\fP (shell layers). (Not implemented on Linux.)
337 (not in POSIX) Mask for input speeds.
341 the same as the values for the
350 (Not implemented on Linux.)
354 Use "stick" (mark/space) parity (supported on certain serial
357 is set, the parity bit is always 1; if
359 is not set, then the parity bit is always 0.
366 (not in POSIX) Enable RTS/CTS (hardware) flow control.
372 \fIc_lflag\fP flag constants:
375 When any of the characters INTR, QUIT, SUSP, or DSUSP are received,
376 generate the corresponding signal.
379 Enable canonical mode (described below).
382 (not in POSIX; not supported under Linux)
383 If \fBICANON\fP is also set, terminal is uppercase only.
384 Input is converted to lowercase, except for characters preceded by \e.
385 On output, uppercase characters are preceded by \e and lowercase
386 characters are converted to uppercase.
393 .\" glibc is probably now wrong to allow
400 Echo input characters.
403 If \fBICANON\fP is also set, the ERASE character erases the preceding
404 input character, and WERASE erases the preceding word.
407 If \fBICANON\fP is also set, the KILL character erases the current line.
410 If \fBICANON\fP is also set, echo the NL character even if ECHO is not set.
413 (not in POSIX) If \fBECHO\fP is also set,
414 terminal special characters other than
415 TAB, NL, START, and STOP are echoed as \fB\(haX\fP,
416 where X is the character with
417 ASCII code 0x40 greater than the special character.
418 For example, character
419 0x08 (BS) is echoed as \fB\(haH\fP.
426 (not in POSIX) If \fBICANON\fP and \fBECHO\fP are also set, characters
427 are printed as they are being erased.
434 (not in POSIX) If \fBICANON\fP is also set, KILL is echoed by erasing
435 each character on the line, as specified by \fBECHOE\fP and \fBECHOPRT\fP.
442 (not in POSIX) Echo only when a process is reading.
443 (Not implemented on Linux.)
446 (not in POSIX; not supported under Linux)
447 Output is being flushed.
448 This flag is toggled by typing
449 the DISCARD character.
456 Disable flushing the input and output queues when generating signals for the
457 INT, QUIT, and SUSP characters.
458 .\" Stevens lets SUSP only flush the input queue
463 signal to the process group of a background process
464 which tries to write to its controlling terminal.
467 (not in POSIX; not supported under Linux)
468 All characters in the input queue are reprinted when
469 the next character is read.
471 handles typeahead this way.)
478 Enable implementation-defined input processing.
479 This flag, as well as \fBICANON\fP must be enabled for the
480 special characters EOL2, LNEXT, REPRINT, WERASE to be interpreted,
481 and for the \fBIUCLC\fP flag to be effective.
483 The \fIc_cc\fP array defines the terminal special characters.
484 The symbolic indices (initial values) and meaning are:
487 (not in POSIX; not supported under Linux; 017, SI, Ctrl-O)
488 Toggle: start/stop discarding pending output.
491 is set, and then not passed as input.
494 (not in POSIX; not supported under Linux; 031, EM, Ctrl-Y)
495 Delayed suspend character (DSUSP):
498 signal when the character is read by the user program.
503 are set, and the system supports
504 job control, and then not passed as input.
508 End-of-file character (EOF).
509 More precisely: this character causes the pending tty buffer to be sent
510 to the waiting user program without waiting for end-of-line.
511 If it is the first character of the line, the
513 in the user program returns 0, which signifies end-of-file.
516 is set, and then not passed as input.
520 Additional end-of-line character (EOL).
526 (not in POSIX; 0, NUL)
527 Yet another end-of-line character (EOL2).
533 (0177, DEL, rubout, or 010, BS, Ctrl-H, or also #)
534 Erase character (ERASE).
535 This erases the previous not-yet-erased character,
536 but does not erase past EOF or beginning-of-line.
539 is set, and then not passed as input.
542 (003, ETX, Ctrl-C, or also 0177, DEL, rubout)
543 Interrupt character (INTR).
549 is set, and then not passed as input.
552 (025, NAK, Ctrl-U, or Ctrl-X, or also @)
553 Kill character (KILL).
554 This erases the input since the last EOF or beginning-of-line.
557 is set, and then not passed as input.
560 (not in POSIX; 026, SYN, Ctrl-V)
561 Literal next (LNEXT).
562 Quotes the next input character, depriving it of
563 a possible special meaning.
566 is set, and then not passed as input.
569 Minimum number of characters for noncanonical read (MIN).
573 Quit character (QUIT).
579 is set, and then not passed as input.
582 (not in POSIX; 022, DC2, Ctrl-R)
583 Reprint unread characters (REPRINT).
588 are set, and then not passed as input.
592 Start character (START).
593 Restarts output stopped by the Stop character.
596 is set, and then not passed as input.
599 (not in POSIX; not supported under Linux;
600 status request: 024, DC4, Ctrl-T).
601 Status character (STATUS).
602 Display status information at terminal,
603 including state of foreground process and amount of CPU time it has consumed.
606 signal (not supported on Linux) to the foreground process group.
610 Stop character (STOP).
611 Stop output until Start character typed.
614 is set, and then not passed as input.
618 Suspend character (SUSP).
624 is set, and then not passed as input.
627 (not in POSIX; not supported under Linux; 0, NUL)
628 Switch character (SWTCH).
629 Used in System V to switch shells in
631 a predecessor to shell job control.
634 Timeout in deciseconds for noncanonical read (TIME).
637 (not in POSIX; 027, ETB, Ctrl-W)
643 are set, and then not passed as input.
645 An individual terminal special character can be disabled by setting
646 the value of the corresponding
649 .BR _POSIX_VDISABLE .
651 The above symbolic subscript values are all different, except that
654 may have the same value as
658 In noncanonical mode the special character meaning is replaced
659 by the timeout meaning.
660 For an explanation of
664 see the description of
665 noncanonical mode below.
666 .SS Retrieving and changing terminal settings
668 gets the parameters associated with the object referred by \fIfd\fP and
669 stores them in the \fItermios\fP structure referenced by
671 This function may be invoked from a background process;
672 however, the terminal attributes may be subsequently changed by a
676 sets the parameters associated with the terminal (unless support is
677 required from the underlying hardware that is not available) from the
678 \fItermios\fP structure referred to by \fItermios_p\fP.
679 \fIoptional_actions\fP specifies when the changes take effect:
681 the change occurs immediately.
683 the change occurs after all output written to
685 has been transmitted.
686 This option should be used when changing
687 parameters that affect output.
689 the change occurs after all output written to the object referred by
691 has been transmitted, and all input that has been received but not read
692 will be discarded before the change is made.
693 .SS Canonical and noncanonical mode
698 determines whether the terminal is operating in canonical mode
710 Input is made available line by line.
711 An input line is available when one of the line delimiters
712 is typed (NL, EOL, EOL2; or EOF at the start of line).
713 Except in the case of EOF, the line delimiter is included
714 in the buffer returned by
717 Line editing is enabled (ERASE, KILL;
720 flag is set: WERASE, REPRINT, LNEXT).
723 returns at most one line of input; if the
725 requested fewer bytes than are available in the current line of input,
726 then only as many bytes as requested are read,
727 and the remaining characters will be available for a future
730 The maximum line length is 4096 chars
731 (including the terminating newline character);
732 lines longer than 4096 chars are truncated.
733 After 4095 characters, input processing (e.g.,
737 processing) continues, but any input data after 4095 characters up to
738 (but not including) any terminating newline is discarded.
739 This ensures that the terminal can always receive
740 more input until at least one line can be read.
742 In noncanonical mode input is available immediately (without
743 the user having to type a line-delimiter character),
744 no input processing is performed,
745 and line editing is disabled.
746 The read buffer will only accept 4095 chars; this provides the
747 necessary space for a newline char if the input mode is switched
753 determine the circumstances in which a
755 completes; there are four distinct cases:
757 MIN == 0, TIME == 0 (polling read)
758 If data is available,
760 returns immediately, with the lesser of the number of bytes
761 available, or the number of bytes requested.
762 If no data is available,
766 MIN > 0, TIME == 0 (blocking read)
768 blocks until MIN bytes are available,
769 and returns up to the number of bytes requested.
771 MIN == 0, TIME > 0 (read with timeout)
772 TIME specifies the limit for a timer in tenths of a second.
773 The timer is started when
777 returns either when at least one byte of data is available,
778 or when the timer expires.
779 If the timer expires without any input becoming available,
782 If data is already available at the time of the call to
784 the call behaves as though the data was received immediately after the call.
786 MIN > 0, TIME > 0 (read with interbyte timeout)
787 TIME specifies the limit for a timer in tenths of a second.
788 Once an initial byte of input becomes available,
789 the timer is restarted after each further byte is received.
791 returns when any of the following conditions is met:
794 MIN bytes have been received.
796 The interbyte timer expires.
798 The number of bytes requested by
801 (POSIX does not specify this termination condition,
802 and on some other implementations
805 does not return in this case.)
808 Because the timer is started only after the initial byte
809 becomes available, at least one byte will be read.
810 If data is already available at the time of the call to
812 the call behaves as though the data was received immediately after the call.
815 .\" POSIX.1-2008 XBD 11.1.7
816 does not specify whether the setting of the
818 file status flag takes precedence over the MIN and TIME settings.
823 in noncanonical mode may return immediately,
824 regardless of the setting of MIN or TIME.
825 Furthermore, if no data is available,
828 in noncanonical mode to return either 0, or \-1 with
834 sets the terminal to something like the
835 "raw" mode of the old Version 7 terminal driver:
836 input is available character by character,
837 echoing is disabled, and all special processing of
838 terminal input and output characters is disabled.
839 The terminal attributes are set as follows:
843 termios_p\->c_iflag &= \(ti(IGNBRK | BRKINT | PARMRK | ISTRIP
844 | INLCR | IGNCR | ICRNL | IXON);
845 termios_p\->c_oflag &= \(tiOPOST;
846 termios_p\->c_lflag &= \(ti(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
847 termios_p\->c_cflag &= \(ti(CSIZE | PARENB);
848 termios_p\->c_cflag |= CS8;
854 transmits a continuous stream of zero-valued bits for a specific
855 duration, if the terminal is using asynchronous serial data
857 If \fIduration\fP is zero, it transmits zero-valued bits
858 for at least 0.25 seconds, and not more than 0.5 seconds.
859 If \fIduration\fP is not zero, it sends zero-valued bits for some
860 implementation-defined length of time.
862 If the terminal is not using asynchronous serial data transmission,
864 returns without taking any action.
867 waits until all output written to the object referred to by
869 has been transmitted.
872 discards data written to the object referred to by
874 but not transmitted, or data received but not read, depending on the
878 flushes data received but not read.
880 flushes data written but not transmitted.
882 flushes both data received but not read, and data written but not
886 suspends transmission or reception of data on the object referred to by
888 depending on the value of
893 restarts suspended output.
895 transmits a STOP character, which stops the terminal device from
896 transmitting data to the system.
898 transmits a START character, which starts the terminal device
899 transmitting data to the system.
901 The default on open of a terminal file is that neither its input nor its
904 The baud rate functions are provided for getting and setting the values
905 of the input and output baud rates in the \fItermios\fP structure.
906 The new values do not take effect
909 is successfully called.
911 Setting the speed to \fBB0\fP instructs the modem to "hang up".
912 The actual bit rate corresponding to \fBB38400\fP may be altered with
915 The input and output baud rates are stored in the \fItermios\fP
919 returns the output baud rate stored in the \fItermios\fP structure
924 sets the output baud rate stored in the \fItermios\fP structure pointed
925 to by \fItermios_p\fP to \fIspeed\fP, which must be one of these constants:
959 These constants are additionally supported on the SPARC architecture:
970 These constants are additionally supported on non-SPARC architectures:
981 Due to differences between architectures, portable applications should check
984 constant is defined prior to using it.
988 is used to terminate the connection.
989 If B0 is specified, the modem control lines shall no longer be asserted.
990 Normally, this will disconnect the line.
993 for the speeds beyond those defined in POSIX.1 (57600 and above).
995 .BR B57600 " & " CBAUDEX
998 Setting the baud rate to a value other than those defined by
1000 constants is possible via the
1006 returns the input baud rate stored in the
1011 sets the input baud rate stored in the
1015 which must be specified as one of the
1017 constants listed above for
1019 If the input baud rate is set to zero, the input baud rate will be
1020 equal to the output baud rate.
1023 is a 4.4BSD extension.
1024 It takes the same arguments as
1026 and sets both input and output speed.
1029 returns the input baud rate stored in the
1034 returns the output baud rate stored in the \fItermios\fP structure.
1036 All other functions return:
1042 to indicate the error.
1046 returns success if \fIany\fP of the requested changes could be
1047 successfully carried out.
1048 Therefore, when making multiple changes
1049 it may be necessary to follow this call with a further call to
1051 to check that all changes have been performed successfully.
1053 For an explanation of the terms used in this section, see
1062 Interface Attribute Value
1076 T} Thread safety MT-Safe
1081 .\" FIXME: The markings are different from that in the glibc manual.
1082 .\" markings in glibc manual are more detailed:
1084 .\" tcsendbreak: MT-Unsafe race:tcattr(filedes)/bsd
1085 .\" tcflow: MT-Unsafe race:tcattr(filedes)/bsd
1087 .\" glibc manual says /bsd indicate the preceding marker only applies
1088 .\" when the underlying kernel is a BSD kernel.
1089 .\" So, it is safety in Linux kernel.
1103 are specified in POSIX.1-2001.
1108 are nonstandard, but available on the BSDs.
1110 UNIX\ V7 and several later systems have a list of baud rates
1111 where after the values
1115 one finds the two constants
1118 ("External A" and "External B").
1119 Many systems extend the list with much higher baud rates.
1121 The effect of a nonzero \fIduration\fP with
1124 SunOS specifies a break of
1126 seconds, where \fIN\fP is at least 0.25, and not more than 0.5.
1127 Linux, AIX, DU, Tru64 send a break of
1130 FreeBSD and NetBSD and HP-UX and MacOS ignore the value of
1132 Under Solaris and UnixWare,
1138 .\" libc4 until 4.7.5, glibc for sysv: EINVAL for duration > 0.
1139 .\" libc4.7.6, libc5, glibc for unix: duration in ms.
1140 .\" glibc for bsd: duration in us
1141 .\" glibc for sunos4: ignore duration
1143 .\" kernel 77e5bff1640432f28794a00800955e646dcd7455
1144 .\" glibc 573963e32ffac46d9891970ddebde2ac3212c5c0
1145 On the Alpha architecture before Linux 4.16 (and glibc before 2.28), the
1147 value was different from
1149 and it was ignored by the
1151 line discipline code of the terminal driver as a result
1152 (because as it wasn't part of the
1162 .BR ioctl_console (2),