1 .\" Hey Emacs! This file is -*- nroff -*- source.
3 .\" Copyright (c) 1993 Michael Haardt
5 .\" Fri Apr 2 11:32:09 MET DST 1993
7 .\" This is free documentation; you can redistribute it and/or
8 .\" modify it under the terms of the GNU General Public License as
9 .\" published by the Free Software Foundation; either version 2 of
10 .\" the License, or (at your option) any later version.
12 .\" The GNU General Public License's references to "object code"
13 .\" and "executables" are to be interpreted as the output of any
14 .\" document formatting or typesetting system, including
15 .\" intermediate and printed output.
17 .\" This manual is distributed in the hope that it will be useful,
18 .\" but WITHOUT ANY WARRANTY; without even the implied warranty of
19 .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 .\" GNU General Public License for more details.
22 .\" You should have received a copy of the GNU General Public
23 .\" License along with this manual; if not, write to the Free
24 .\" Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111,
27 .\" Modified 1993-07-24 by Rik Faith <faith@cs.unc.edu>
28 .\" Modified 1995-02-25 by Jim Van Zandt <jrv@vanzandt.mv.com>
29 .\" Modified 1995-09-02 by Jim Van Zandt <jrv@vanzandt.mv.com>
30 .\" moved to man3, aeb, 950919
31 .\" Modified 2001-09-22 by Michael Kerrisk <mtk.manpages@gmail.com>
32 .\" Modified 2001-12-17, aeb
33 .\" Modified 2004-10-31, aeb
35 .\" Added .SS headers to give some structure to this page; and a
36 .\" small amount of reordering.
37 .\" Added a section on canonical and noncanonical mode.
38 .\" Enhanced the discussion of "raw" mode for cfmakeraw().
41 .TH TERMIOS 3 2007-11-26 "Linux" "Linux Programmer's Manual"
43 termios, tcgetattr, tcsetattr, tcsendbreak, tcdrain, tcflush, tcflow,
44 cfmakeraw, cfgetospeed, cfgetispeed, cfsetispeed, cfsetospeed, cfsetspeed \-
45 get and set terminal attributes, line control, get and set baud rate
48 .B #include <termios.h>
50 .B #include <unistd.h>
52 .BI "int tcgetattr(int " fd ", struct termios *" termios_p );
54 .BI "int tcsetattr(int " fd ", int " optional_actions ,
55 .BI " const struct termios *" termios_p );
57 .BI "int tcsendbreak(int " fd ", int " duration );
59 .BI "int tcdrain(int " fd );
61 .BI "int tcflush(int " fd ", int " queue_selector );
63 .BI "int tcflow(int " fd ", int " action );
65 .BI "void cfmakeraw(struct termios *" termios_p );
67 .BI "speed_t cfgetispeed(const struct termios *" termios_p );
69 .BI "speed_t cfgetospeed(const struct termios *" termios_p );
71 .BI "int cfsetispeed(struct termios *" termios_p ", speed_t " speed );
73 .BI "int cfsetospeed(struct termios *" termios_p ", speed_t " speed );
75 .BI "int cfsetspeed(struct termios *" termios_p ", speed_t " speed );
79 Feature Test Macro Requirements for glibc (see
80 .BR feature_test_macros (7)):
87 The termios functions describe a general terminal interface that is
88 provided to control asynchronous communications ports.
89 .SS "The termios structure"
91 Many of the functions described here have a \fItermios_p\fP argument
92 that is a pointer to a \fItermios\fP structure.
93 This structure contains at least the following members:
97 tcflag_t c_iflag; /* input modes */
98 tcflag_t c_oflag; /* output modes */
99 tcflag_t c_cflag; /* control modes */
100 tcflag_t c_lflag; /* local modes */
101 cc_t c_cc[NCCS]; /* control chars */
105 The values that may be assigned to these fields are described below.
106 In the case of the first four bit-mask fields,
107 the definitions of some of the associated flags that may be set are
108 only exposed if a specific feature test macro (see
109 .BR feature_test_macros (7))
110 is defined, as noted in brackets ("[]").
112 In the descriptions below, "not in POSIX" means that the
113 value is not specified in POSIX.1-2001,
114 and "XSI" means that the value is specified in POSIX.1-2001
115 as part of the XSI extension.
117 \fIc_iflag\fP flag constants:
120 Ignore BREAK condition on input.
123 If \fBIGNBRK\fP is set, a BREAK is ignored.
125 but \fBBRKINT\fP is set, then a BREAK causes the input and output
126 queues to be flushed, and if the terminal is the controlling
127 terminal of a foreground process group, it will cause a
128 \fBSIGINT\fP to be sent to this foreground process group.
129 When neither \fBIGNBRK\fP nor \fBBRKINT\fP are set, a BREAK
130 reads as a null byte (\(aq\\0\(aq), except when \fBPARMRK\fP is set,
131 in which case it reads as the sequence \\377 \\0 \\0.
134 Ignore framing errors and parity errors.
137 If \fBIGNPAR\fP is not set, prefix a character with a parity error or
138 framing error with \\377 \\0.
139 If neither \fBIGNPAR\fP nor \fBPARMRK\fP
140 is set, read a character with a parity error or framing error
144 Enable input parity checking.
147 Strip off eighth bit.
150 Translate NL to CR on input.
153 Ignore carriage return on input.
156 Translate carriage return to newline on input (unless \fBIGNCR\fP is set).
159 (not in POSIX) Map uppercase characters to lowercase on input.
162 Enable XON/XOFF flow control on output.
165 (XSI) Typing any character will restart stopped output.
166 (The default is to allow just the START character to restart output.)
169 Enable XON/XOFF flow control on input.
172 (not in POSIX) Ring bell when input queue is full.
173 Linux does not implement this bit, and acts as if it is always set.
175 .BR IUTF8 " (since Linux 2.6.4)"
176 (not in POSIX) Input is UTF8;
177 this allows character-erase to be correctly performed in cooked mode.
179 \fIc_oflag\fP flag constants defined in POSIX.1:
182 Enable implementation-defined output processing.
184 The remaining \fIc_oflag\fP flag constants are defined in POSIX.1-2001,
185 unless marked otherwise.
188 (not in POSIX) Map lowercase characters to uppercase on output.
191 (XSI) Map NL to CR-NL on output.
194 Map CR to NL on output.
197 Don't output CR at column 0.
203 Send fill characters for a delay, rather than using a timed delay.
206 (not in POSIX) Fill character is ASCII DEL (0177).
207 If unset, fill character is ASCII NUL (\(aq\\0\(aq).
208 (Not implemented on Linux.)
212 Values are \fBNL0\fP and \fBNL1\fP.
221 Carriage return delay mask.
222 Values are \fBCR0\fP, \fBCR1\fP, \fBCR2\fP, or \fBCR3\fP.
231 Horizontal tab delay mask.
232 Values are \fBTAB0\fP, \fBTAB1\fP, \fBTAB2\fP, \fBTAB3\fP (or \fBXTABS\fP).
233 A value of TAB3, that is, XTABS, expands tabs to spaces
234 (with tab stops every eight columns).
243 Backspace delay mask.
244 Values are \fBBS0\fP or \fBBS1\fP.
245 (Has never been implemented.)
254 Vertical tab delay mask.
255 Values are \fBVT0\fP or \fBVT1\fP.
258 Form feed delay mask.
259 Values are \fBFF0\fP or \fBFF1\fP.
267 \fIc_cflag\fP flag constants:
270 (not in POSIX) Baud speed mask (4+1 bits).
277 (not in POSIX) Extra baud speed mask (1 bit), included in
284 (POSIX says that the baud speed is stored in the
286 structure without specifying where precisely, and provides
291 Some systems use bits selected by
295 other systems use separate fields, for example,
302 Values are \fBCS5\fP, \fBCS6\fP, \fBCS7\fP, or \fBCS8\fP.
305 Set two stop bits, rather than one.
311 Enable parity generation on output and parity checking for input.
314 If set, then parity for input and output is odd;
315 otherwise even parity is used.
318 Lower modem control lines after last process closes the device (hang up).
321 Ignore modem control lines.
324 (not in POSIX) Block output from a noncurrent shell layer.
325 For use by \fBshl\fP (shell layers). (Not implemented on Linux.)
328 (not in POSIX) Mask for input speeds.
332 the same as the values for the
341 (Not implemented on Linux.)
345 Use "stick" (mark/space) parity (supported on certain serial
348 is set, the parity bit is always 1; if
350 is not set, then the parity bit is always 0).
357 (not in POSIX) Enable RTS/CTS (hardware) flow control.
363 \fIc_lflag\fP flag constants:
366 When any of the characters INTR, QUIT, SUSP, or DSUSP are received,
367 generate the corresponding signal.
370 Enable canonical mode (described below).
373 (not in POSIX; not supported under Linux)
374 If \fBICANON\fP is also set, terminal is uppercase only.
375 Input is converted to lowercase, except for characters preceded by \\.
376 On output, uppercase characters are preceded by \\ and lowercase
377 characters are converted to uppercase.
378 [requires _BSD_SOURCE or _SVID_SOURCE or _XOPEN_SOURCE]
379 .\" glibc is probably now wrong to allow
386 Echo input characters.
389 If \fBICANON\fP is also set, the ERASE character erases the preceding
390 input character, and WERASE erases the preceding word.
393 If \fBICANON\fP is also set, the KILL character erases the current line.
396 If \fBICANON\fP is also set, echo the NL character even if ECHO is not set.
399 (not in POSIX) If \fBECHO\fP is also set, ASCII control signals other than
400 TAB, NL, START, and STOP are echoed as \fB^X\fP,
401 where X is the character with
402 ASCII code 0x40 greater than the control signal.
403 For example, character
404 0x08 (BS) is echoed as \fB^H\fP.
411 (not in POSIX) If \fBICANON\fP and \fBIECHO\fP are also set, characters
412 are printed as they are being erased.
419 (not in POSIX) If \fBICANON\fP is also set, KILL is echoed by erasing
420 each character on the line, as specified by \fBECHOE\fP and \fBECHOPRT\fP.
427 (not in POSIX) Echo only when a process is reading.
428 (Not implemented on Linux.)
431 (not in POSIX; not supported under Linux)
432 Output is being flushed.
433 This flag is toggled by typing
434 the DISCARD character.
441 Disable flushing the input and output queues when generating the
447 .\" Stevens lets SIGSUSP only flush the input queue
452 signal to the process group of a background process
453 which tries to write to its controlling terminal.
456 (not in POSIX; not supported under Linux)
457 All characters in the input queue are reprinted when
458 the next character is read.
460 handles typeahead this way.)
467 Enable implementation-defined input processing.
468 This flag, as well as \fBICANON\fP must be enabled for the
469 special characters EOL2, LNEXT, REPRINT, WERASE to be interpreted,
470 and for the \fBIUCLC\fP flag to be effective.
472 The \fIc_cc\fP array defines the special control characters.
473 The symbolic indices (initial values) and meaning are:
476 (003, ETX, Ctrl-C, or also 0177, DEL, rubout)
483 is set, and then not passed as input.
493 is set, and then not passed as input.
496 (0177, DEL, rubout, or 010, BS, Ctrl-H, or also #)
498 This erases the previous not-yet-erased character,
499 but does not erase past EOF or beginning-of-line.
502 is set, and then not passed as input.
505 (025, NAK, Ctrl-U, or Ctrl-X, or also @)
507 This erases the input since the last EOF or beginning-of-line.
510 is set, and then not passed as input.
514 End-of-file character.
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.
525 Minimum number of characters for noncanonical read.
529 Additional end-of-line character.
535 Timeout in deciseconds for noncanonical read.
538 (not in POSIX; 0, NUL)
539 Yet another end-of-line character.
545 (not in POSIX; not supported under Linux; 0, NUL)
547 (Used by \fBshl\fP only.)
552 Restarts output stopped by the Stop character.
555 is set, and then not passed as input.
560 Stop output until Start character typed.
563 is set, and then not passed as input.
573 is set, and then not passed as input.
576 (not in POSIX; not supported under Linux; 031, EM, Ctrl-Y)
577 Delayed suspend character:
580 signal when the character is read by the user program.
585 are set, and the system supports
586 job control, and then not passed as input.
589 (not in POSIX; 026, SYN, Ctrl-V)
591 Quotes the next input character, depriving it of
592 a possible special meaning.
595 is set, and then not passed as input.
598 (not in POSIX; 027, ETB, Ctrl-W)
604 are set, and then not passed as input.
607 (not in POSIX; 022, DC2, Ctrl-R)
608 Reprint unread characters.
613 are set, and then not passed as input.
616 (not in POSIX; not supported under Linux; 017, SI, Ctrl-O)
617 Toggle: start/stop discarding pending output.
620 is set, and then not passed as input.
623 (not in POSIX; not supported under Linux;
624 status request: 024, DC4, Ctrl-T).
626 These symbolic subscript values are all different, except that
629 may have the same value as
633 In noncanonical mode the special character meaning is replaced
634 by the timeout meaning.
635 For an explanation of
639 see the description of
640 noncanonical mode below.
641 .SS "Retrieving and changing terminal settings"
644 gets the parameters associated with the object referred by \fIfd\fP and
645 stores them in the \fItermios\fP structure referenced by
647 This function may be invoked from a background process;
648 however, the terminal attributes may be subsequently changed by a
652 sets the parameters associated with the terminal (unless support is
653 required from the underlying hardware that is not available) from the
654 \fItermios\fP structure referred to by \fItermios_p\fP.
655 \fIoptional_actions\fP specifies when the changes take effect:
657 the change occurs immediately.
659 the change occurs after all output written to
661 has been transmitted.
662 This function should be used when changing
663 parameters that affect output.
665 the change occurs after all output written to the object referred by
667 has been transmitted, and all input that has been received but not read
668 will be discarded before the change is made.
669 .SS "Canonical and noncanonical mode"
674 determines whether the terminal is operating in canonical mode
686 Input is made available line by line.
687 An input line is available when one of the line delimiters
688 is typed (NL, EOL, EOL2; or EOF at the start of line).
689 Except in the case of EOF, the line delimiter is included
690 in the buffer returned by
693 Line editing is enabled (ERASE, KILL;
696 flag is set: WERASE, REPRINT, LNEXT).
699 returns at most one line of input; if the
701 requested fewer bytes than are available in the current line of input,
702 then only as many bytes as requested are read,
703 and the remaining characters will be available for a future
706 In noncanonical mode input is available immediately (without
707 the user having to type a line-delimiter character),
708 and line editing is disabled.
713 determine the circumstances in which a
715 completes; there are four distinct cases:
718 If data is available,
720 returns immediately, with the lesser of the number of bytes
721 available, or the number of bytes requested.
722 If no data is available,
728 blocks until the lesser of MIN bytes or the number of bytes requested
729 are available, and returns the lesser of these two values.
732 TIME specifies the limit for a timer in tenths of a second.
733 The timer is started when
737 returns either when at least one byte of data is available,
738 or when the timer expires.
739 If the timer expires without any input becoming available,
744 TIME specifies the limit for a timer in tenths of a second.
745 Once an initial byte of input becomes available,
746 the timer is restarted after each further byte is received.
748 returns either when the lesser of the number of bytes requested or
749 MIN byte have been read,
750 or when the inter-byte timeout expires.
751 Because the timer is only started after the initial byte
752 becomes available, at least one byte will be read.
756 sets the terminal to something like the
757 "raw" mode of the old Version 7 terminal driver:
758 input is available character by character,
759 echoing is disabled, and all special processing of
760 terminal input and output characters is disabled.
761 The terminal attributes are set as follows:
764 termios_p\->c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP
765 | INLCR | IGNCR | ICRNL | IXON);
766 termios_p\->c_oflag &= ~OPOST;
767 termios_p\->c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
768 termios_p\->c_cflag &= ~(CSIZE | PARENB);
769 termios_p\->c_cflag |= CS8;
774 transmits a continuous stream of zero-valued bits for a specific
775 duration, if the terminal is using asynchronous serial data
777 If \fIduration\fP is zero, it transmits zero-valued bits
778 for at least 0.25 seconds, and not more that 0.5 seconds.
779 If \fIduration\fP is not zero, it sends zero-valued bits for some
780 implementation-defined length of time.
782 If the terminal is not using asynchronous serial data transmission,
784 returns without taking any action.
787 waits until all output written to the object referred to by
789 has been transmitted.
792 discards data written to the object referred to by
794 but not transmitted, or data received but not read, depending on the
798 flushes data received but not read.
800 flushes data written but not transmitted.
802 flushes both data received but not read, and data written but not
806 suspends transmission or reception of data on the object referred to by
808 depending on the value of
813 restarts suspended output.
815 transmits a STOP character, which stops the terminal device from
816 transmitting data to the system.
818 transmits a START character, which starts the terminal device
819 transmitting data to the system.
821 The default on open of a terminal file is that neither its input nor its
824 The baud rate functions are provided for getting and setting the values
825 of the input and output baud rates in the \fItermios\fP structure.
826 The new values do not take effect
829 is successfully called.
831 Setting the speed to \fBB0\fP instructs the modem to "hang up".
832 The actual bit rate corresponding to \fBB38400\fP may be altered with
835 The input and output baud rates are stored in the \fItermios\fP
839 returns the output baud rate stored in the \fItermios\fP structure
844 sets the output baud rate stored in the \fItermios\fP structure pointed
845 to by \fItermios_p\fP to \fIspeed\fP, which must be one of these constants:
871 The zero baud rate, \fBB0\fP,
872 is used to terminate the connection.
873 If B0 is specified, the modem control lines shall no longer be asserted.
874 Normally, this will disconnect the line.
875 \fBCBAUDEX\fP is a mask
876 for the speeds beyond those defined in POSIX.1 (57600 and above).
877 Thus, \fBB57600\fP & \fBCBAUDEX\fP is nonzero.
880 returns the input baud rate stored in the \fItermios\fP structure.
883 sets the input baud rate stored in the \fItermios\fP structure to
885 which must be specified as one of the \fBBnnn\fP constants listed above for
887 If the input baud rate is set to zero, the input baud rate will be
888 equal to the output baud rate.
891 is a 4.4BSD extension.
892 It takes the same arguments as
894 and sets both input and output speed.
898 returns the input baud rate stored in the
903 returns the output baud rate stored in the \fItermios\fP structure.
905 All other functions return:
911 to indicate the error.
915 returns success if \fIany\fP of the requested changes could be
916 successfully carried out.
917 Therefore, when making multiple changes
918 it may be necessary to follow this call with a further call to
920 to check that all changes have been performed successfully.
933 are specified in POSIX.1-2001.
938 are nonstandard, but available on the BSDs.
940 Unix V7 and several later systems have a list of baud rates
941 where after the fourteen values B0, ..., B9600 one finds the
942 two constants EXTA, EXTB ("External A" and "External B").
943 Many systems extend the list with much higher baud rates.
945 The effect of a nonzero \fIduration\fP with
948 SunOS specifies a break of
950 seconds, where \fIN\fP is at least 0.25, and not more than 0.5.
951 Linux, AIX, DU, Tru64 send a break of
954 FreeBSD and NetBSD and HP-UX and MacOS ignore the value of
956 Under Solaris and Unixware,
962 .\" libc4 until 4.7.5, glibc for sysv: EINVAL for duration > 0.
963 .\" libc4.7.6, libc5, glibc for unix: duration in ms.
964 .\" glibc for bsd: duration in us
965 .\" glibc for sunos4: ignore duration
968 .BR console_ioctl (4),