1 .\" Copyright (c) 1993 Michael Haardt
3 .\" Fri Apr 2 11:32:09 MET DST 1993
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 2019-03-06 "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 );
52 .BI "int tcsetattr(int " fd ", int " optional_actions ,
53 .BI " const struct termios *" termios_p );
55 .BI "int tcsendbreak(int " fd ", int " duration );
57 .BI "int tcdrain(int " fd );
59 .BI "int tcflush(int " fd ", int " queue_selector );
61 .BI "int tcflow(int " fd ", int " action );
63 .BI "void cfmakeraw(struct termios *" termios_p );
65 .BI "speed_t cfgetispeed(const struct termios *" termios_p );
67 .BI "speed_t cfgetospeed(const struct termios *" termios_p );
69 .BI "int cfsetispeed(struct termios *" termios_p ", speed_t " speed );
71 .BI "int cfsetospeed(struct termios *" termios_p ", speed_t " speed );
73 .BI "int cfsetspeed(struct termios *" termios_p ", speed_t " speed );
77 Feature Test Macro Requirements for glibc (see
78 .BR feature_test_macros (7)):
85 Glibc 2.19 and earlier:
88 The termios functions describe a general terminal interface that is
89 provided to control asynchronous communications ports.
90 .SS The termios structure
92 Many of the functions described here have a \fItermios_p\fP argument
93 that is a pointer to a \fItermios\fP structure.
94 This structure contains at least the following members:
98 tcflag_t c_iflag; /* input modes */
99 tcflag_t c_oflag; /* output modes */
100 tcflag_t c_cflag; /* control modes */
101 tcflag_t c_lflag; /* local modes */
102 cc_t c_cc[NCCS]; /* special characters */
106 The values that may be assigned to these fields are described below.
107 In the case of the first four bit-mask fields,
108 the definitions of some of the associated flags that may be set are
109 exposed only if a specific feature test macro (see
110 .BR feature_test_macros (7))
111 is defined, as noted in brackets ("[]").
113 In the descriptions below, "not in POSIX" means that the
114 value is not specified in POSIX.1-2001,
115 and "XSI" means that the value is specified in POSIX.1-2001
116 as part of the XSI extension.
118 \fIc_iflag\fP flag constants:
121 Ignore BREAK condition on input.
124 If \fBIGNBRK\fP is set, a BREAK is ignored.
126 but \fBBRKINT\fP is set, then a BREAK causes the input and output
127 queues to be flushed, and if the terminal is the controlling
128 terminal of a foreground process group, it will cause a
129 \fBSIGINT\fP to be sent to this foreground process group.
130 When neither \fBIGNBRK\fP nor \fBBRKINT\fP are set, a BREAK
131 reads as a null byte (\(aq\e0\(aq), except when \fBPARMRK\fP is set,
132 in which case it reads as the sequence \e377 \e0 \e0.
135 Ignore framing errors and parity errors.
138 If this bit is set, input bytes with parity or framing errors are
139 marked when passed to the program.
140 This bit is meaningful only when
141 \fBINPCK\fP is set and \fBIGNPAR\fP is not set.
142 The way erroneous bytes are marked is with two preceding bytes,
144 Thus, the program actually reads three bytes for one
145 erroneous byte received from the terminal.
146 If a valid byte has the value \e377,
147 and \fBISTRIP\fP (see below) is not set,
148 the program might confuse it with the prefix that marks a
150 Therefore, a valid byte \e377 is passed to the program as two
151 bytes, \e377 \e377, in this case.
153 If neither \fBIGNPAR\fP nor \fBPARMRK\fP
154 is set, read a character with a parity error or framing error
158 Enable input parity checking.
161 Strip off eighth bit.
164 Translate NL to CR on input.
167 Ignore carriage return on input.
170 Translate carriage return to newline on input (unless \fBIGNCR\fP is set).
173 (not in POSIX) Map uppercase characters to lowercase on input.
176 Enable XON/XOFF flow control on output.
179 (XSI) Typing any character will restart stopped output.
180 (The default is to allow just the START character to restart output.)
183 Enable XON/XOFF flow control on input.
186 (not in POSIX) Ring bell when input queue is full.
187 Linux does not implement this bit, and acts as if it is always set.
189 .BR IUTF8 " (since Linux 2.6.4)"
190 (not in POSIX) Input is UTF8;
191 this allows character-erase to be correctly performed in cooked mode.
197 Enable implementation-defined output processing.
200 (not in POSIX) Map lowercase characters to uppercase on output.
203 (XSI) Map NL to CR-NL on output.
206 Map CR to NL on output.
209 Don't output CR at column 0.
215 Send fill characters for a delay, rather than using a timed delay.
218 Fill character is ASCII DEL (0177).
219 If unset, fill character is ASCII NUL (\(aq\e0\(aq).
220 (Not implemented on Linux.)
224 Values are \fBNL0\fP and \fBNL1\fP.
233 Carriage return delay mask.
234 Values are \fBCR0\fP, \fBCR1\fP, \fBCR2\fP, or \fBCR3\fP.
243 Horizontal tab delay mask.
244 Values are \fBTAB0\fP, \fBTAB1\fP, \fBTAB2\fP, \fBTAB3\fP (or \fBXTABS\fP,
248 A value of TAB3, that is, XTABS, expands tabs to spaces
249 (with tab stops every eight columns).
258 Backspace delay mask.
259 Values are \fBBS0\fP or \fBBS1\fP.
260 (Has never been implemented.)
269 Vertical tab delay mask.
270 Values are \fBVT0\fP or \fBVT1\fP.
273 Form feed delay mask.
274 Values are \fBFF0\fP or \fBFF1\fP.
282 \fIc_cflag\fP flag constants:
285 (not in POSIX) Baud speed mask (4+1 bits).
292 (not in POSIX) Extra baud speed mask (1 bit), included in
299 (POSIX says that the baud speed is stored in the
301 structure without specifying where precisely, and provides
306 Some systems use bits selected by
310 other systems use separate fields, for example,
317 Values are \fBCS5\fP, \fBCS6\fP, \fBCS7\fP, or \fBCS8\fP.
320 Set two stop bits, rather than one.
326 Enable parity generation on output and parity checking for input.
329 If set, then parity for input and output is odd;
330 otherwise even parity is used.
333 Lower modem control lines after last process closes the device (hang up).
336 Ignore modem control lines.
339 (not in POSIX) Block output from a noncurrent shell layer.
340 For use by \fBshl\fP (shell layers). (Not implemented on Linux.)
343 (not in POSIX) Mask for input speeds.
347 the same as the values for the
356 (Not implemented on Linux.)
360 Use "stick" (mark/space) parity (supported on certain serial
363 is set, the parity bit is always 1; if
365 is not set, then the parity bit is always 0.
372 (not in POSIX) Enable RTS/CTS (hardware) flow control.
378 \fIc_lflag\fP flag constants:
381 When any of the characters INTR, QUIT, SUSP, or DSUSP are received,
382 generate the corresponding signal.
385 Enable canonical mode (described below).
388 (not in POSIX; not supported under Linux)
389 If \fBICANON\fP is also set, terminal is uppercase only.
390 Input is converted to lowercase, except for characters preceded by \e.
391 On output, uppercase characters are preceded by \e and lowercase
392 characters are converted to uppercase.
399 .\" glibc is probably now wrong to allow
406 Echo input characters.
409 If \fBICANON\fP is also set, the ERASE character erases the preceding
410 input character, and WERASE erases the preceding word.
413 If \fBICANON\fP is also set, the KILL character erases the current line.
416 If \fBICANON\fP is also set, echo the NL character even if ECHO is not set.
419 (not in POSIX) If \fBECHO\fP is also set,
420 terminal special characters other than
421 TAB, NL, START, and STOP are echoed as \fB^X\fP,
422 where X is the character with
423 ASCII code 0x40 greater than the special character.
424 For example, character
425 0x08 (BS) is echoed as \fB^H\fP.
432 (not in POSIX) If \fBICANON\fP and \fBECHO\fP are also set, characters
433 are printed as they are being erased.
440 (not in POSIX) If \fBICANON\fP is also set, KILL is echoed by erasing
441 each character on the line, as specified by \fBECHOE\fP and \fBECHOPRT\fP.
448 (not in POSIX) Echo only when a process is reading.
449 (Not implemented on Linux.)
452 (not in POSIX; not supported under Linux)
453 Output is being flushed.
454 This flag is toggled by typing
455 the DISCARD character.
462 Disable flushing the input and output queues when generating signals for the
463 INT, QUIT, and SUSP characters.
464 .\" Stevens lets SUSP only flush the input queue
469 signal to the process group of a background process
470 which tries to write to its controlling terminal.
473 (not in POSIX; not supported under Linux)
474 All characters in the input queue are reprinted when
475 the next character is read.
477 handles typeahead this way.)
484 Enable implementation-defined input processing.
485 This flag, as well as \fBICANON\fP must be enabled for the
486 special characters EOL2, LNEXT, REPRINT, WERASE to be interpreted,
487 and for the \fBIUCLC\fP flag to be effective.
489 The \fIc_cc\fP array defines the terminal special characters.
490 The symbolic indices (initial values) and meaning are:
493 (not in POSIX; not supported under Linux; 017, SI, Ctrl-O)
494 Toggle: start/stop discarding pending output.
497 is set, and then not passed as input.
500 (not in POSIX; not supported under Linux; 031, EM, Ctrl-Y)
501 Delayed suspend character (DSUSP):
504 signal when the character is read by the user program.
509 are set, and the system supports
510 job control, and then not passed as input.
514 End-of-file character (EOF).
515 More precisely: this character causes the pending tty buffer to be sent
516 to the waiting user program without waiting for end-of-line.
517 If it is the first character of the line, the
519 in the user program returns 0, which signifies end-of-file.
522 is set, and then not passed as input.
526 Additional end-of-line character (EOL).
532 (not in POSIX; 0, NUL)
533 Yet another end-of-line character (EOL2).
539 (0177, DEL, rubout, or 010, BS, Ctrl-H, or also #)
540 Erase character (ERASE).
541 This erases the previous not-yet-erased character,
542 but does not erase past EOF or beginning-of-line.
545 is set, and then not passed as input.
548 (003, ETX, Ctrl-C, or also 0177, DEL, rubout)
549 Interrupt character (INTR).
555 is set, and then not passed as input.
558 (025, NAK, Ctrl-U, or Ctrl-X, or also @)
559 Kill character (KILL).
560 This erases the input since the last EOF or beginning-of-line.
563 is set, and then not passed as input.
566 (not in POSIX; 026, SYN, Ctrl-V)
567 Literal next (LNEXT).
568 Quotes the next input character, depriving it of
569 a possible special meaning.
572 is set, and then not passed as input.
575 Minimum number of characters for noncanonical read (MIN).
579 Quit character (QUIT).
585 is set, and then not passed as input.
588 (not in POSIX; 022, DC2, Ctrl-R)
589 Reprint unread characters (REPRINT).
594 are set, and then not passed as input.
598 Start character (START).
599 Restarts output stopped by the Stop character.
602 is set, and then not passed as input.
605 (not in POSIX; not supported under Linux;
606 status request: 024, DC4, Ctrl-T).
607 Status character (STATUS).
608 Display status information at terminal,
609 including state of foreground process and amount of CPU time it has consumed.
612 signal (not supported on Linux) to the foreground process group.
616 Stop character (STOP).
617 Stop output until Start character typed.
620 is set, and then not passed as input.
624 Suspend character (SUSP).
630 is set, and then not passed as input.
633 (not in POSIX; not supported under Linux; 0, NUL)
634 Switch character (SWTCH).
635 Used in System V to switch shells in
637 a predecessor to shell job control.
640 Timeout in deciseconds for noncanonical read (TIME).
643 (not in POSIX; 027, ETB, Ctrl-W)
649 are set, and then not passed as input.
651 An individual terminal special character can be disabled by setting
652 the value of the corresponding
655 .BR _POSIX_VDISABLE .
657 The above symbolic subscript values are all different, except that
660 may have the same value as
664 In noncanonical mode the special character meaning is replaced
665 by the timeout meaning.
666 For an explanation of
670 see the description of
671 noncanonical mode below.
672 .SS Retrieving and changing terminal settings
675 gets the parameters associated with the object referred by \fIfd\fP and
676 stores them in the \fItermios\fP structure referenced by
678 This function may be invoked from a background process;
679 however, the terminal attributes may be subsequently changed by a
683 sets the parameters associated with the terminal (unless support is
684 required from the underlying hardware that is not available) from the
685 \fItermios\fP structure referred to by \fItermios_p\fP.
686 \fIoptional_actions\fP specifies when the changes take effect:
688 the change occurs immediately.
690 the change occurs after all output written to
692 has been transmitted.
693 This option should be used when changing
694 parameters that affect output.
696 the change occurs after all output written to the object referred by
698 has been transmitted, and all input that has been received but not read
699 will be discarded before the change is made.
700 .SS Canonical and noncanonical mode
705 determines whether the terminal is operating in canonical mode
717 Input is made available line by line.
718 An input line is available when one of the line delimiters
719 is typed (NL, EOL, EOL2; or EOF at the start of line).
720 Except in the case of EOF, the line delimiter is included
721 in the buffer returned by
724 Line editing is enabled (ERASE, KILL;
727 flag is set: WERASE, REPRINT, LNEXT).
730 returns at most one line of input; if the
732 requested fewer bytes than are available in the current line of input,
733 then only as many bytes as requested are read,
734 and the remaining characters will be available for a future
737 The maximum line length is 4096 chars
738 (including the terminating newline character);
739 lines longer than 4096 chars are truncated.
740 After 4095 characters, input processing (e.g.,
744 processing) continues, but any input data after 4095 characters up to
745 (but not including) any terminating newline is discarded.
746 This ensures that the terminal can always receive
747 more input until at least one line can be read.
749 In noncanonical mode input is available immediately (without
750 the user having to type a line-delimiter character),
751 no input processing is performed,
752 and line editing is disabled.
753 The read buffer will only accept 4095 chars; this provides the
754 necessary space for a newline char if the input mode is switched
760 determine the circumstances in which a
762 completes; there are four distinct cases:
764 MIN == 0, TIME == 0 (polling read)
765 If data is available,
767 returns immediately, with the lesser of the number of bytes
768 available, or the number of bytes requested.
769 If no data is available,
773 MIN > 0, TIME == 0 (blocking read)
775 blocks until MIN bytes are available,
776 and returns up to the number of bytes requested.
778 MIN == 0, TIME > 0 (read with timeout)
779 TIME specifies the limit for a timer in tenths of a second.
780 The timer is started when
784 returns either when at least one byte of data is available,
785 or when the timer expires.
786 If the timer expires without any input becoming available,
789 If data is already available at the time of the call to
791 the call behaves as though the data was received immediately after the call.
793 MIN > 0, TIME > 0 (read with interbyte timeout)
794 TIME specifies the limit for a timer in tenths of a second.
795 Once an initial byte of input becomes available,
796 the timer is restarted after each further byte is received.
798 returns when any of the following conditions is met:
801 MIN bytes have been received.
803 The interbyte timer expires.
805 The number of bytes requested by
808 (POSIX does not specify this termination condition,
809 and on some other implementations
812 does not return in this case.)
815 Because the timer is started only after the initial byte
816 becomes available, at least one byte will be read.
817 If data is already available at the time of the call to
819 the call behaves as though the data was received immediately after the call.
822 .\" POSIX.1-2008 XBD 11.1.7
823 does not specify whether the setting of the
825 file status flag takes precedence over the MIN and TIME settings.
830 in noncanonical mode may return immediately,
831 regardless of the setting of MIN or TIME.
832 Furthermore, if no data is available,
835 in noncanonical mode to return either 0, or \-1 with
842 sets the terminal to something like the
843 "raw" mode of the old Version 7 terminal driver:
844 input is available character by character,
845 echoing is disabled, and all special processing of
846 terminal input and output characters is disabled.
847 The terminal attributes are set as follows:
851 termios_p\->c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP
852 | INLCR | IGNCR | ICRNL | IXON);
853 termios_p\->c_oflag &= ~OPOST;
854 termios_p\->c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
855 termios_p\->c_cflag &= ~(CSIZE | PARENB);
856 termios_p\->c_cflag |= CS8;
863 transmits a continuous stream of zero-valued bits for a specific
864 duration, if the terminal is using asynchronous serial data
866 If \fIduration\fP is zero, it transmits zero-valued bits
867 for at least 0.25 seconds, and not more that 0.5 seconds.
868 If \fIduration\fP is not zero, it sends zero-valued bits for some
869 implementation-defined length of time.
871 If the terminal is not using asynchronous serial data transmission,
873 returns without taking any action.
876 waits until all output written to the object referred to by
878 has been transmitted.
881 discards data written to the object referred to by
883 but not transmitted, or data received but not read, depending on the
887 flushes data received but not read.
889 flushes data written but not transmitted.
891 flushes both data received but not read, and data written but not
895 suspends transmission or reception of data on the object referred to by
897 depending on the value of
902 restarts suspended output.
904 transmits a STOP character, which stops the terminal device from
905 transmitting data to the system.
907 transmits a START character, which starts the terminal device
908 transmitting data to the system.
910 The default on open of a terminal file is that neither its input nor its
913 The baud rate functions are provided for getting and setting the values
914 of the input and output baud rates in the \fItermios\fP structure.
915 The new values do not take effect
918 is successfully called.
920 Setting the speed to \fBB0\fP instructs the modem to "hang up".
921 The actual bit rate corresponding to \fBB38400\fP may be altered with
924 The input and output baud rates are stored in the \fItermios\fP
928 returns the output baud rate stored in the \fItermios\fP structure
933 sets the output baud rate stored in the \fItermios\fP structure pointed
934 to by \fItermios_p\fP to \fIspeed\fP, which must be one of these constants:
960 The zero baud rate, \fBB0\fP,
961 is used to terminate the connection.
962 If B0 is specified, the modem control lines shall no longer be asserted.
963 Normally, this will disconnect the line.
964 \fBCBAUDEX\fP is a mask
965 for the speeds beyond those defined in POSIX.1 (57600 and above).
966 Thus, \fBB57600\fP & \fBCBAUDEX\fP is nonzero.
969 returns the input baud rate stored in the \fItermios\fP structure.
972 sets the input baud rate stored in the \fItermios\fP structure to
974 which must be specified as one of the \fBBnnn\fP constants listed above for
976 If the input baud rate is set to zero, the input baud rate will be
977 equal to the output baud rate.
980 is a 4.4BSD extension.
981 It takes the same arguments as
983 and sets both input and output speed.
987 returns the input baud rate stored in the
992 returns the output baud rate stored in the \fItermios\fP structure.
994 All other functions return:
1000 to indicate the error.
1004 returns success if \fIany\fP of the requested changes could be
1005 successfully carried out.
1006 Therefore, when making multiple changes
1007 it may be necessary to follow this call with a further call to
1009 to check that all changes have been performed successfully.
1011 For an explanation of the terms used in this section, see
1019 Interface Attribute Value
1033 T} Thread safety MT-Safe
1035 .\" FIXME: The markings are different from that in the glibc manual.
1036 .\" markings in glibc manual are more detailed:
1038 .\" tcsendbreak: MT-Unsafe race:tcattr(filedes)/bsd
1039 .\" tcflow: MT-Unsafe race:tcattr(filedes)/bsd
1041 .\" glibc manual says /bsd indicate the preceding marker only applies
1042 .\" when the underlying kernel is a BSD kernel.
1043 .\" So, it is safety in Linux kernel.
1058 are specified in POSIX.1-2001.
1063 are nonstandard, but available on the BSDs.
1065 UNIX\ V7 and several later systems have a list of baud rates
1066 where after the fourteen values B0, ..., B9600 one finds the
1067 two constants EXTA, EXTB ("External A" and "External B").
1068 Many systems extend the list with much higher baud rates.
1070 The effect of a nonzero \fIduration\fP with
1073 SunOS specifies a break of
1075 seconds, where \fIN\fP is at least 0.25, and not more than 0.5.
1076 Linux, AIX, DU, Tru64 send a break of
1079 FreeBSD and NetBSD and HP-UX and MacOS ignore the value of
1081 Under Solaris and UnixWare,
1087 .\" libc4 until 4.7.5, glibc for sysv: EINVAL for duration > 0.
1088 .\" libc4.7.6, libc5, glibc for unix: duration in ms.
1089 .\" glibc for bsd: duration in us
1090 .\" glibc for sunos4: ignore duration
1092 .\" kernel 77e5bff1640432f28794a00800955e646dcd7455
1093 .\" glibc 573963e32ffac46d9891970ddebde2ac3212c5c0
1094 On the Alpha architecture before Linux 4.16 (and glibc before 2.28), the
1096 value was different from
1098 and it was ignored by the
1100 line discipline code of the terminal driver as a result
1101 (because as it wasn't part of the
1111 .BR ioctl_console (2),