1.\" Copyright (c) 1991, 1992, 1993 2.\" The Regents of the University of California. All rights reserved. 3.\" 4.\" Redistribution and use in source and binary forms, with or without 5.\" modification, are permitted provided that the following conditions 6.\" are met: 7.\" 1. Redistributions of source code must retain the above copyright 8.\" notice, this list of conditions and the following disclaimer. 9.\" 2. Redistributions in binary form must reproduce the above copyright 10.\" notice, this list of conditions and the following disclaimer in the 11.\" documentation and/or other materials provided with the distribution. 12.\" 3. Neither the name of the University nor the names of its contributors 13.\" may be used to endorse or promote products derived from this software 14.\" without specific prior written permission. 15.\" 16.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 17.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 20.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26.\" SUCH DAMAGE. 27.\" 28.\" @(#)termios.4 8.4 (Berkeley) 4/19/94 29.\" $FreeBSD: src/share/man/man4/termios.4,v 1.12.2.9 2001/12/17 11:30:12 ru Exp $ 30.\" 31.Dd December 31, 2017 32.Dt TERMIOS 4 33.Os 34.Sh NAME 35.Nm termios 36.Nd general terminal line discipline 37.Sh SYNOPSIS 38.In termios.h 39.Sh DESCRIPTION 40This describes a general terminal line discipline that is 41supported on tty asynchronous communication ports. 42.Ss Opening a Terminal Device File 43When a terminal file is opened, it normally causes the process to wait 44until a connection is established. 45For most hardware, the presence 46of a connection is indicated by the assertion of the hardware 47.Dv CARRIER 48line. 49If the termios structure associated with the terminal file has the 50.Dv CLOCAL 51flag set in the cflag, or if the 52.Dv O_NONBLOCK 53flag is set 54in the 55.Xr open 2 56call, then the open will succeed even without 57a connection being present. 58In practice, applications 59seldom open these files; they are opened by special programs, such 60as 61.Xr getty 8 62or 63.Xr rlogind 8 Pq Pa net/bsdrcmds , 64and become 65an application's standard input, output, and error files. 66.Ss Job Control in a Nutshell 67Every process is associated with a particular process group and session. 68The grouping is hierarchical: every member of a particular process group is a 69member of the same session. 70This structuring is used in managing groups 71of related processes for purposes of 72.\" .Gw "job control" ; 73.Em "job control" ; 74that is, the 75ability from the keyboard (or from program control) to simultaneously 76stop or restart 77a complex command (a command composed of one or more related 78processes). 79The grouping into process groups allows delivering 80of signals that stop or start the group as a whole, along with 81arbitrating which process group has access to the single controlling 82terminal. 83The grouping at a higher layer into sessions is to restrict 84the job control related signals and system calls to within processes 85resulting from a particular instance of a 86.Dq login . 87Typically, a session 88is created when a user logs in, and the login terminal is setup 89to be the controlling terminal; all processes spawned from that 90login shell are in the same session, and inherit the controlling 91terminal. 92.Pp 93A job control shell 94operating interactively (that is, reading commands from a terminal) 95normally groups related processes together by placing them into the 96same process group. 97A set of processes in the same process group is collectively referred to as a 98.Dq job . 99When the foreground process 100group of the terminal is the same as the process group of a particular 101job, that job is said to be in the 102.Dq foreground . 103When the process group of the terminal is different from the process group of 104a job (but is still the controlling terminal), that job is said 105to be in the 106.Dq background . 107Normally the 108shell reads a command and starts the job that implements that 109command. 110If the command is to be started in the foreground (typical), it 111sets the process group of the terminal to the process group 112of the started job, waits for the job to complete, and then 113sets the process group of the terminal back to its own process 114group (it puts itself into the foreground). 115If the job is to 116be started in the background (as denoted by the shell operator "&"), 117it never changes the process group of the terminal and does not 118wait for the job to complete (that is, it immediately attempts to read the next 119command). 120If the job is started in the foreground, the user may 121type a key (usually 122.Ql \&^Z ) 123which generates the terminal stop signal 124.Pq Dv SIGTSTP 125and has the effect of stopping the entire job. 126The shell will notice that the job stopped, and will resume running after 127placing itself in the foreground. 128The shell also has commands for placing stopped jobs in the background, 129and for placing stopped or background jobs into the foreground. 130.Ss Orphaned Process Groups 131An orphaned process group is a process group that has no process 132whose parent is in a different process group, yet is in the same 133session. 134Conceptually it means a process group that does not have 135a parent that could do anything if it were to be stopped. 136For example, 137the initial login shell is typically in an orphaned process group. 138Orphaned process groups are immune to keyboard generated stop 139signals and job control signals resulting from reads or writes to the 140controlling terminal. 141.Ss The Controlling Terminal 142A terminal may belong to a process as its controlling terminal. 143Each process of a session that has a controlling terminal has the same 144controlling terminal. 145A terminal may be the controlling terminal for at most one session. 146The controlling terminal for a session is allocated by 147the session leader by issuing the 148.Dv TIOCSCTTY 149ioctl. 150A controlling terminal 151is never acquired by merely opening a terminal device file. 152When a controlling terminal becomes 153associated with a session, its foreground process group is set to 154the process group of the session leader. 155.Pp 156The controlling terminal is inherited by a child process during a 157.Xr fork 2 158function call. 159A process relinquishes its controlling terminal when it 160creates a new session with the 161.Xr setsid 2 162function; other processes 163remaining in the old session that had this terminal as their controlling 164terminal continue to have it. 165A process does not relinquish its 166controlling terminal simply by closing all of its file descriptors 167associated with the controlling terminal if other processes continue to 168have it open. 169.Pp 170When a controlling process terminates, the controlling terminal is 171disassociated from the current session, allowing it to be acquired by a 172new session leader. 173Subsequent access to the terminal by other processes 174in the earlier session will be denied, with attempts to access the 175terminal treated as if modem disconnect had been sensed. 176.Ss Terminal Access Control 177If a process is in the foreground process group of its controlling 178terminal, read operations are allowed. 179Any attempts by a process 180in a background process group to read from its controlling terminal 181causes a 182.Dv SIGTTIN 183signal to be sent to 184the process's group 185unless one of the 186following special cases apply: if the reading process is ignoring or 187blocking the 188.Dv SIGTTIN 189signal, or if the process group of the reading 190process is orphaned, the 191.Xr read 2 192returns -1 with 193.Va errno 194set to 195.Er EIO 196and no 197signal is sent. 198The default action of the 199.Dv SIGTTIN 200signal is to stop the 201process to which it is sent. 202.Pp 203If a process is in the foreground process group of its controlling 204terminal, write operations are allowed. 205Attempts by a process in a background process group to write to its 206controlling terminal will cause the process group to be sent a 207.Dv SIGTTOU 208signal unless one of the following special cases apply: if 209.Dv TOSTOP 210is not 211set, or if 212.Dv TOSTOP 213is set and the process is ignoring or blocking the 214.Dv SIGTTOU 215signal, the process is allowed to write to the terminal and the 216.Dv SIGTTOU 217signal is not sent. 218If 219.Dv TOSTOP 220is set, and the process group of 221the writing process is orphaned, and the writing process is not ignoring 222or blocking 223.Dv SIGTTOU , 224the 225.Xr write 2 226returns -1 with 227.Va errno 228set to 229.Er EIO 230and no signal is sent. 231.Pp 232Certain calls that set terminal parameters are treated in the same 233fashion as write, except that 234.Dv TOSTOP 235is ignored; that is, the effect is 236identical to that of terminal writes when 237.Dv TOSTOP 238is set. 239.Ss Input Processing and Reading Data 240A terminal device associated with a terminal device file may operate in 241full-duplex mode, so that data may arrive even while output is occurring. 242Each terminal device file has associated with it an input queue, into 243which incoming data is stored by the system before being read by a 244process. 245The system imposes a limit, 246.Pf \&{ Dv MAX_INPUT Ns \&} , 247on the number of bytes that may be stored in the input queue. 248The behavior of the system 249when this limit is exceeded depends on the setting of the 250.Dv IMAXBEL 251flag in the termios 252.Fa c_iflag . 253If this flag is set, the terminal 254is sent an 255.Tn ASCII 256.Dv BEL 257character each time a character is received 258while the input queue is full. 259Otherwise, the input queue is flushed upon receiving the character. 260.Pp 261Two general kinds of input processing are available, determined by 262whether the terminal device file is in canonical mode or noncanonical 263mode. 264Additionally, 265input characters are processed according to the 266.Fa c_iflag 267and 268.Fa c_lflag 269fields. 270Such processing can include echoing, which 271in general means transmitting input characters immediately back to the 272terminal when they are received from the terminal. 273This is useful for terminals that can operate in full-duplex mode. 274.Pp 275The manner in which data is provided to a process reading from a terminal 276device file is dependent on whether the terminal device file is in 277canonical or noncanonical mode. 278.Pp 279Another dependency is whether the 280.Dv O_NONBLOCK 281flag is set by 282.Xr open 2 283or 284.Xr fcntl 2 . 285If the 286.Dv O_NONBLOCK 287flag is clear, then the read request is 288blocked until data is available or a signal has been received. 289If the 290.Dv O_NONBLOCK 291flag is set, then the read request is completed, without 292blocking, in one of three ways: 293.Bl -enum -offset indent 294.It 295If there is enough data available to satisfy the entire request, 296and the read completes successfully the number of 297bytes read is returned. 298.It 299If there is not enough data available to satisfy the entire 300request, and the read completes successfully, having read as 301much data as possible, the number of bytes read is returned. 302.It 303If there is no data available, the read returns -1, with 304.Va errno 305set to 306.Er EAGAIN . 307.El 308.Pp 309When data is available depends on whether the input processing mode is 310canonical or noncanonical. 311.Ss Canonical Mode Input Processing 312In canonical mode input processing, terminal input is processed in units 313of lines. 314A line is delimited by a newline 315.Ql \&\en 316character, an end-of-file 317.Pq Dv EOF 318character, or an end-of-line 319.Pq Dv EOL 320character. 321See the 322.Sx "Special Characters" 323section for more information on 324.Dv EOF 325and 326.Dv EOL . 327This means that a read request will 328not return until an entire line has been typed, or a signal has been 329received. 330Also, no matter how many bytes are requested in the read call, 331at most one line is returned. 332It is not, however, necessary to 333read a whole line at once; any number of bytes, even one, may be 334requested in a read without losing information. 335.Pp 336.Pf \&{ Dv MAX_CANON Ns \&} 337is a limit on the 338number of bytes in a line. 339The behavior of the system when this limit is 340exceeded is the same as when the input queue limit 341.Pf \&{ Dv MAX_INPUT Ns \&} , 342is exceeded. 343.Pp 344Erase and kill processing occur when either of two special characters, 345the 346.Dv ERASE 347and 348.Dv KILL 349characters (see the 350.Sx "Special Characters" 351section), is received. 352This processing affects data in the input queue that has not yet been 353delimited by a newline 354.Dv NL , 355.Dv EOF , 356or 357.Dv EOL 358character. 359This un-delimited data makes up the current line. 360The 361.Dv ERASE 362character deletes the last character in the current line, if there is any. 363The 364.Dv KILL 365character 366deletes all data in the current line, if there is any. 367The 368.Dv ERASE 369and 370.Dv KILL 371characters have no effect if there is no data in the current line. 372The 373.Dv ERASE 374and 375.Dv KILL 376characters themselves are not placed in the input 377queue. 378.Ss Noncanonical Mode Input Processing 379In noncanonical mode input processing, input bytes are not assembled into 380lines, and erase and kill processing does not occur. 381The values of the 382.Dv VMIN 383and 384.Dv VTIME 385members of the 386.Fa c_cc 387array are used to determine how to 388process the bytes received. 389.Pp 390.Dv MIN 391represents the minimum number of bytes that should be received when 392the 393.Xr read 2 394function successfully returns. 395.Dv TIME 396is a timer of 0.1 second 397granularity that is used to time out bursty and short term data 398transmissions. 399If 400.Dv MIN 401is greater than 402.Dv \&{ Dv MAX_INPUT Ns \&} , 403the response to the 404request is undefined. 405The four possible values for 406.Dv MIN 407and 408.Dv TIME 409and 410their interactions are described below. 411.Ss "Case A: MIN > 0, TIME > 0" 412In this case 413.Dv TIME 414serves as an inter-byte timer and is activated after 415the first byte is received. 416Since it is an inter-byte timer, it is reset after a byte is received. 417The interaction between 418.Dv MIN 419and 420.Dv TIME 421is as 422follows: as soon as one byte is received, the inter-byte timer is 423started. 424If 425.Dv MIN 426bytes are received before the inter-byte timer expires 427(remember that the timer is reset upon receipt of each byte), the read is 428satisfied. 429If the timer expires before 430.Dv MIN 431bytes are received, the 432characters received to that point are returned to the user. 433Note that if 434.Dv TIME 435expires at least one byte is returned because the timer would 436not have been enabled unless a byte was received. 437In this case 438.Pf \&( Dv MIN 439> 0, 440.Dv TIME 441> 0) the read blocks until the 442.Dv MIN 443and 444.Dv TIME 445mechanisms are 446activated by the receipt of the first byte, or a signal is received. 447If data is in the buffer at the time of the 448.Fn read , 449the result is as 450if data had been received immediately after the 451.Fn read . 452.Ss "Case B: MIN > 0, TIME = 0" 453In this case, since the value of 454.Dv TIME 455is zero, the timer plays no role 456and only 457.Dv MIN 458is significant. 459A pending read is not satisfied until 460.Dv MIN 461bytes are received (i.e., the pending read blocks until 462.Dv MIN 463bytes 464are received), or a signal is received. 465A program that uses this case to read record-based terminal 466.Dv I/O 467may block indefinitely in the read 468operation. 469.Ss "Case C: MIN = 0, TIME > 0" 470In this case, since 471.Dv MIN 472= 0, 473.Dv TIME 474no longer represents an inter-byte 475timer. 476It now serves as a read timer that is activated as soon as the 477read function is processed. 478A read is satisfied as soon as a single 479byte is received or the read timer expires. 480Note that in this case if the timer expires, no bytes are returned. 481If the timer does not 482expire, the only way the read can be satisfied is if a byte is received. 483In this case the read will not block indefinitely waiting for a byte; if 484no byte is received within 485.Dv TIME Ns *0.1 486seconds after the read is initiated, 487the read returns a value of zero, having read no data. 488If data is in the buffer at the time of the read, the timer is started as if 489data had been received immediately after the read. 490.Ss Case D: MIN = 0, TIME = 0 491The minimum of either the number of bytes requested or the number of 492bytes currently available is returned without waiting for more 493bytes to be input. 494If no characters are available, read returns a 495value of zero, having read no data. 496.Ss Writing Data and Output Processing 497When a process writes one or more bytes to a terminal device file, they 498are processed according to the 499.Fa c_oflag 500field (see the 501.Sx "Output Modes" 502section). 503The implementation may provide a buffering mechanism; as such, when a call to 504.Fn write 505completes, all of the bytes written have been scheduled for 506transmission to the device, but the transmission will not necessarily 507have been completed. 508.\" See also .Sx "6.4.2" for the effects of 509.\" .Dv O_NONBLOCK 510.\" on write. 511.Ss Special Characters 512Certain characters have special functions on input or output or both. 513These functions are summarized as follows: 514.Bl -tag -width indent 515.It Dv INTR 516Special character on input and is recognized if the 517.Dv ISIG 518flag (see the 519.Sx "Local Modes" 520section) is enabled. 521Generates a 522.Dv SIGINT 523signal which is sent to all processes in the foreground 524process group for which the terminal is the controlling terminal. 525If 526.Dv ISIG 527is set, the 528.Dv INTR 529character is 530discarded when processed. 531.It Dv QUIT 532Special character on input and is recognized if the 533.Dv ISIG 534flag is enabled. 535Generates a 536.Dv SIGQUIT 537signal which is sent to all processes in the foreground process group 538for which the terminal is the controlling terminal. 539If 540.Dv ISIG 541is set, the 542.Dv QUIT 543character is discarded when 544processed. 545.It Dv ERASE 546Special character on input and is recognized if the 547.Dv ICANON 548flag is set. 549Erases the last character in the current line; see 550.Sx "Canonical Mode Input Processing" . 551It does not erase beyond 552the start of a line, as delimited by an 553.Dv NL , 554.Dv EOF , 555or 556.Dv EOL 557character. 558If 559.Dv ICANON 560is set, the 561.Dv ERASE 562character is 563discarded when processed. 564.It Dv KILL 565Special character on input and is recognized if the 566.Dv ICANON 567flag is set. 568Deletes the entire line, as delimited by a 569.Dv NL , 570.Dv EOF , 571or 572.Dv EOL 573character. 574If 575.Dv ICANON 576is set, the 577.Dv KILL 578character is discarded when processed. 579.It Dv EOF 580Special character on input and is recognized if the 581.Dv ICANON 582flag is set. 583When received, all the bytes waiting to be read are immediately passed to the 584process, without waiting for a newline, and the 585.Dv EOF 586is discarded. 587Thus, if there are no bytes waiting (that is, the 588.Dv EOF 589occurred at the beginning of a line), a byte 590count of zero is returned from the 591.Fn read , 592representing an end-of-file indication. 593If 594.Dv ICANON 595is 596set, the 597.Dv EOF 598character is discarded when processed. 599.It Dv NL 600Special character on input and is recognized if the 601.Dv ICANON 602flag is set. 603It is the line delimiter 604.Ql \&\en . 605.It Dv EOL 606Special character on input and is recognized if the 607.Dv ICANON 608flag is set. 609Is an additional line delimiter, like 610.Dv NL . 611.It Dv SUSP 612If the 613.Dv ISIG 614flag is enabled, receipt of the 615.Dv SUSP 616character causes a 617.Dv SIGTSTP 618signal to be sent to all processes in the 619foreground process group for which the terminal is the 620controlling terminal, and the 621.Dv SUSP 622character is 623discarded when processed. 624.It Dv STOP 625Special character on both input and output and is 626recognized if the 627.Dv IXON 628(output control) or 629.Dv IXOFF 630(input 631control) flag is set. 632Can be used to temporarily suspend output. 633It is useful with fast terminals to 634prevent output from disappearing before it can be read. 635If 636.Dv IXON 637is set, the 638.Dv STOP 639character is discarded when 640processed. 641.It Dv START 642Special character on both input and output and is 643recognized if the 644.Dv IXON 645(output control) or 646.Dv IXOFF 647(input 648control) flag is set. 649Can be used to resume output that has been suspended by a 650.Dv STOP 651character. 652If 653.Dv IXON 654is set, the 655.Dv START 656character is discarded when processed. 657.It Dv CR 658Special character on input and is recognized if the 659.Dv ICANON 660flag is set; it is the 661.Ql \&\er , 662as denoted in the 663.Tn \&C 664Standard {2}. 665When 666.Dv ICANON 667and 668.Dv ICRNL 669are set and 670.Dv IGNCR 671is not set, this character is translated into a 672.Dv NL , 673and 674has the same effect as a 675.Dv NL 676character. 677.El 678.Pp 679The following special characters are extensions defined by this 680system and are not a part of 681.St -p1003.1 682termios. 683.Bl -tag -width indent 684.It Dv EOL2 685Secondary 686.Dv EOL 687character. 688Same function as 689.Dv EOL . 690.It Dv WERASE 691Special character on input and is recognized if the 692.Dv ICANON 693flag is set. 694Erases the last word in the current line according to one of two algorithms. 695If the 696.Dv ALTWERASE 697flag is not set, first any preceding whitespace is 698erased, and then the maximal sequence of non-whitespace 699characters. 700If 701.Dv ALTWERASE 702is set, first any preceding 703whitespace is erased, and then the maximal sequence 704of alphabetic/underscores or non alphabetic/underscores. 705As a special case in this second algorithm, the first previous 706non-whitespace character is skipped in determining 707whether the preceding word is a sequence of 708alphabetic/underscores. 709This sounds confusing but turns out to be quite practical. 710.It Dv REPRINT 711Special character on input and is recognized if the 712.Dv ICANON 713flag is set. 714Causes the current input edit line to be retyped. 715.It Dv DSUSP 716Has similar actions to the 717.Dv SUSP 718character, except that 719the 720.Dv SIGTSTP 721signal is delivered when one of the processes 722in the foreground process group issues a 723.Fn read 724to the 725controlling terminal. 726.It Dv LNEXT 727Special character on input and is recognized if the 728.Dv IEXTEN 729flag is set. 730Receipt of this character causes the next character to be taken literally. 731.It Dv DISCARD 732Special character on input and is recognized if the 733.Dv IEXTEN 734flag is set. 735Receipt of this character toggles the flushing of terminal output. 736.It Dv STATUS 737Special character on input and is recognized if the 738.Dv ICANON 739flag is set. 740Receipt of this character causes a 741.Dv SIGINFO 742signal to be sent to the foreground process group of the terminal. 743Also, if the 744.Dv NOKERNINFO 745flag is not set, it 746causes the kernel to write a status message to the terminal 747that displays the current load average, the name of the 748command in the foreground, its process ID, the symbolic 749wait channel, the number of user and system seconds used, 750the percentage of cpu the process is getting, and the resident 751set size of the process. 752.El 753.Pp 754The 755.Dv NL 756and 757.Dv CR 758characters cannot be changed. 759The values for all the remaining characters can be set and are 760described later in the document under 761Special Control Characters. 762.Pp 763Special 764character functions associated with changeable special control characters 765can be disabled individually by setting their value to 766.Dv {_POSIX_VDISABLE} ; 767see 768.Sx "Special Control Characters" . 769.Pp 770If two or more special characters have the same value, the function 771performed when that character is received is undefined. 772.Ss Modem Disconnect 773If a modem disconnect is detected by the terminal interface for a 774controlling terminal, and if 775.Dv CLOCAL 776is not set in the 777.Fa c_cflag 778field for 779the terminal, the 780.Dv SIGHUP 781signal is sent to the controlling 782process associated with the terminal. 783Unless other arrangements have 784been made, this causes the controlling process to terminate. 785Any subsequent call to the 786.Fn read 787function returns the value zero, 788indicating end of file. 789Thus, processes that read a terminal 790file and test for end-of-file can terminate appropriately after a 791disconnect. 792.\" If the 793.\" .Er EIO 794.\" condition specified in 6.1.1.4 that applies 795.\" when the implementation supports job control also exists, it is 796.\" unspecified whether the 797.\" .Dv EOF 798.\" condition or the 799.\" .Pf [ Er EIO 800.\" ] is returned. 801Any 802subsequent 803.Fn write 804to the terminal device returns -1, with 805.Va errno 806set to 807.Er EIO , 808until the device is closed. 809.Sh General Terminal Interface 810.Ss Closing a Terminal Device File 811The last process to close a terminal device file causes any output 812to be sent to the device and any input to be discarded. 813Then, if 814.Dv HUPCL 815is set in the control modes, and the communications port supports a 816disconnect function, the terminal device performs a disconnect. 817.Ss Parameters That Can Be Set 818Routines that need to control certain terminal 819.Tn I/O 820characteristics 821do so by using the termios structure as defined in the header 822.In termios.h . 823This structure contains minimally four scalar elements of bit flags 824and one array of special characters. 825The scalar flag elements are named: 826.Fa c_iflag , 827.Fa c_oflag , 828.Fa c_cflag , 829and 830.Fa c_lflag . 831The character array is named 832.Fa c_cc , 833and its maximum index is 834.Dv NCCS . 835.Ss Input Modes 836Values of the 837.Fa c_iflag 838field describe the basic 839terminal input control, and are composed of 840following masks: 841.Pp 842.Bl -tag -width IMAXBEL -offset indent -compact 843.It Dv IGNBRK 844/* ignore BREAK condition */ 845.It Dv BRKINT 846/* map BREAK to SIGINTR */ 847.It Dv IGNPAR 848/* ignore (discard) parity errors */ 849.It Dv PARMRK 850/* mark parity and framing errors */ 851.It Dv INPCK 852/* enable checking of parity errors */ 853.It Dv ISTRIP 854/* strip 8th bit off chars */ 855.It Dv INLCR 856/* map NL into CR */ 857.It Dv IGNCR 858/* ignore CR */ 859.It Dv ICRNL 860/* map CR to NL (ala CRMOD) */ 861.It Dv IXON 862/* enable output flow control */ 863.It Dv IXOFF 864/* enable input flow control */ 865.It Dv IXANY 866/* any char will restart after stop */ 867.It Dv IMAXBEL 868/* ring bell on input queue full */ 869.El 870.Pp 871In the context of asynchronous serial data transmission, a break 872condition is defined as a sequence of zero-valued bits that continues for 873more than the time to send one byte. 874The entire sequence of zero-valued 875bits is interpreted as a single break condition, even if it continues for 876a time equivalent to more than one byte. 877In contexts other than 878asynchronous serial data transmission the definition of a break condition 879is implementation defined. 880.Pp 881If 882.Dv IGNBRK 883is set, a break condition detected on input is ignored, that 884is, not put on the input queue and therefore not read by any process. 885If 886.Dv IGNBRK 887is not set and 888.Dv BRKINT 889is set, the break condition flushes the 890input and output queues and if the terminal is the controlling terminal 891of a foreground process group, the break condition generates a 892single 893.Dv SIGINT 894signal to that foreground process group. 895If neither 896.Dv IGNBRK 897nor 898.Dv BRKINT 899is set, a break condition is read as a single 900.Ql \&\e0 , 901or if 902.Dv PARMRK 903is set, as 904.Ql \&\e377 , 905.Ql \&\e0 , 906.Ql \&\e0 . 907.Pp 908If 909.Dv IGNPAR 910is set, a byte with a framing or parity error (other than 911break) is ignored. 912.Pp 913If 914.Dv PARMRK 915is set, and 916.Dv IGNPAR 917is not set, a byte with a framing or parity 918error (other than break) is given to the application as the 919three-character sequence 920.Ql \&\e377 , 921.Ql \&\e0 , 922X, where 923.Ql \&\e377 , 924.Ql \&\e0 925is a two-character 926flag preceding each sequence and X is the data of the character received 927in error. 928To avoid ambiguity in this case, if 929.Dv ISTRIP 930is not set, a valid 931character of 932.Ql \&\e377 933is given to the application as 934.Ql \&\e377 , 935.Ql \&\e377 . 936If 937neither 938.Dv PARMRK 939nor 940.Dv IGNPAR 941is set, a framing or parity error (other than 942break) is given to the application as a single character 943.Ql \&\e0 . 944.Pp 945If 946.Dv INPCK 947is set, input parity checking is enabled. 948If 949.Dv INPCK 950is not set, 951input parity checking is disabled, allowing output parity generation 952without input parity errors. 953Note that whether input parity checking is 954enabled or disabled is independent of whether parity detection is enabled 955or disabled (see 956.Sx "Control Modes" ) . 957If parity detection is enabled but input 958parity checking is disabled, the hardware to which the terminal is 959connected recognizes the parity bit, but the terminal special file 960does not check whether this bit is set correctly or not. 961.Pp 962If 963.Dv ISTRIP 964is set, valid input bytes are first stripped to seven bits, 965otherwise all eight bits are processed. 966.Pp 967If 968.Dv INLCR 969is set, a received 970.Dv NL 971character is translated into a 972.Dv CR 973character. 974If 975.Dv IGNCR 976is set, a received 977.Dv CR 978character is ignored (not 979read). 980If 981.Dv IGNCR 982is not set and 983.Dv ICRNL 984is set, a received 985.Dv CR 986character is 987translated into a 988.Dv NL 989character. 990.Pp 991If 992.Dv IXON 993is set, start/stop output control is enabled. 994A received 995.Dv STOP 996character suspends output and a received 997.Dv START 998character 999restarts output. 1000If 1001.Dv IXANY 1002is also set, then any character may 1003restart output. 1004When 1005.Dv IXON 1006is set, 1007.Dv START 1008and 1009.Dv STOP 1010characters are not read, but merely perform flow control functions. 1011When 1012.Dv IXON 1013is not set, 1014the 1015.Dv START 1016and 1017.Dv STOP 1018characters are read. 1019.Pp 1020If 1021.Dv IXOFF 1022is set, start/stop input control is enabled. 1023The system shall transmit one or more 1024.Dv STOP 1025characters, which are intended to cause the 1026terminal device to stop transmitting data, as needed to prevent the input 1027queue from overflowing and causing the undefined behavior described in 1028.Sx "Input Processing and Reading Data" , 1029and shall transmit one or more 1030.Dv START 1031characters, which are 1032intended to cause the terminal device to resume transmitting data, as 1033soon as the device can continue transmitting data without risk of 1034overflowing the input queue. 1035The precise conditions under which 1036.Dv STOP 1037and 1038.Dv START 1039characters are transmitted are implementation defined. 1040.Pp 1041If 1042.Dv IMAXBEL 1043is set and the input queue is full, subsequent input shall cause an 1044.Tn ASCII 1045.Dv BEL 1046character to be transmitted to 1047the output queue. 1048.Pp 1049The initial input control value after 1050.Fn open 1051is implementation defined. 1052.Ss Output Modes 1053Values of the 1054.Fa c_oflag 1055field describe the basic terminal output control, 1056and are composed of the following masks: 1057.Pp 1058.Bl -tag -width OXTABS -offset indent -compact 1059.It Dv OPOST 1060/* enable following output processing */ 1061.It Dv ONLCR 1062/* map NL to CR-NL (ala 1063.Dv CRMOD ) 1064*/ 1065.It Dv OCRNL 1066/* map CR to NL */ 1067.It Dv OXTABS 1068/* expand tabs to spaces */ 1069.It Dv ONOEOT 1070/* discard 1071.Dv EOT Ns 's 1072.Ql \&^D 1073on output) */ 1074.It Dv ONOCR 1075/* do not transmit CRs on column 0 */ 1076.It Dv ONLRET 1077/* on the terminal NL performs the CR function */ 1078.El 1079.Pp 1080If 1081.Dv OPOST 1082is set, the remaining flag masks are interpreted as follows; 1083otherwise characters are transmitted without change. 1084.Pp 1085If 1086.Dv ONLCR 1087is set, newlines are translated to carriage return, linefeeds. 1088.Pp 1089If 1090.Dv OCRNL 1091is set, carriage returns are translated to newlines. 1092.Pp 1093If 1094.Dv OXTABS 1095is set, tabs are expanded to the appropriate number of 1096spaces (assuming 8 column tab stops). 1097.Pp 1098If 1099.Dv ONOEOT 1100is set, 1101.Tn ASCII 1102.Dv EOT Ns 's 1103are discarded on output. 1104.Pp 1105If 1106.Dv ONOCR 1107is set, no CR character is transmitted when at column 0 (first position). 1108.Pp 1109If 1110.Dv ONLRET 1111is set, the NL character is assumed to do the carriage-return function; 1112the column pointer will be set to 0. 1113.Ss Control Modes 1114Values of the 1115.Fa c_cflag 1116field describe the basic 1117terminal hardware control, and are composed of the 1118following masks. 1119Not all values 1120specified are supported by all hardware. 1121.Pp 1122.Bl -tag -width CRTSXIFLOW -offset indent -compact 1123.It Dv CSIZE 1124/* character size mask */ 1125.It Dv CS5 1126/* 5 bits (pseudo) */ 1127.It Dv CS6 1128/* 6 bits */ 1129.It Dv CS7 1130/* 7 bits */ 1131.It Dv CS8 1132/* 8 bits */ 1133.It Dv CSTOPB 1134/* send 2 stop bits */ 1135.It Dv CREAD 1136/* enable receiver */ 1137.It Dv PARENB 1138/* parity enable */ 1139.It Dv PARODD 1140/* odd parity, else even */ 1141.It Dv HUPCL 1142/* hang up on last close */ 1143.It Dv CLOCAL 1144/* ignore modem status lines */ 1145.It Dv CCTS_OFLOW 1146/* 1147.Dv CTS 1148flow control of output */ 1149.It Dv CRTSCTS 1150/* same as 1151.Dv CCTS_OFLOW 1152*/ 1153.It Dv CRTS_IFLOW 1154/* RTS flow control of input */ 1155.It Dv MDMBUF 1156/* flow control output via Carrier */ 1157.El 1158.Pp 1159The 1160.Dv CSIZE 1161bits specify the byte size in bits for both transmission and reception. 1162The 1163.Fa c_cflag 1164is masked with 1165.Dv CSIZE 1166and compared with the 1167values 1168.Dv CS5 , 1169.Dv CS6 , 1170.Dv CS7 , 1171or 1172.Dv CS8 . 1173This size does not include the parity bit, if any. 1174If 1175.Dv CSTOPB 1176is set, two stop bits are used, otherwise one stop bit. 1177For example, at 110 baud, two stop bits are normally used. 1178.Pp 1179If 1180.Dv CREAD 1181is set, the receiver is enabled. 1182Otherwise, no character is received. 1183Not all hardware supports this bit. 1184In fact, this flag is pretty silly and if it were not part of the 1185.Nm 1186specification 1187it would be omitted. 1188.Pp 1189If 1190.Dv PARENB 1191is set, parity generation and detection are enabled and a parity 1192bit is added to each character. 1193If parity is enabled, 1194.Dv PARODD 1195specifies odd parity if set, otherwise even parity is used. 1196.Pp 1197If 1198.Dv HUPCL 1199is set, the modem control lines for the port are lowered 1200when the last process with the port open closes the port or the process 1201terminates. 1202The modem connection is broken. 1203.Pp 1204If 1205.Dv CLOCAL 1206is set, a connection does not depend on the state of the modem 1207status lines. 1208If 1209.Dv CLOCAL 1210is clear, the modem status lines are monitored. 1211.Pp 1212Under normal circumstances, a call to the 1213.Fn open 1214function waits for the modem connection to complete. 1215However, if the 1216.Dv O_NONBLOCK 1217flag is set or if 1218.Dv CLOCAL 1219has been set, the 1220.Fn open 1221function returns 1222immediately without waiting for the connection. 1223.Pp 1224The 1225.Dv CCTS_OFLOW 1226.Pf ( Dv CRTSCTS ) 1227flag is currently unused. 1228.Pp 1229If 1230.Dv MDMBUF 1231is set then output flow control is controlled by the state 1232of Carrier Detect. 1233.Pp 1234If the object for which the control modes are set is not an asynchronous 1235serial connection, some of the modes may be ignored; for example, if an 1236attempt is made to set the baud rate on a network connection to a 1237terminal on another host, the baud rate may or may not be set on the 1238connection between that terminal and the machine it is directly connected 1239to. 1240.Ss Local Modes 1241Values of the 1242.Fa c_lflag 1243field describe the control of 1244various functions, and are composed of the following 1245masks. 1246.Pp 1247.Bl -tag -width NOKERNINFO -offset indent -compact 1248.It Dv ECHOKE 1249/* visual erase for line kill */ 1250.It Dv ECHOE 1251/* visually erase chars */ 1252.It Dv ECHO 1253/* enable echoing */ 1254.It Dv ECHONL 1255/* echo 1256.Dv NL 1257even if 1258.Dv ECHO 1259is off */ 1260.It Dv ECHOPRT 1261/* visual erase mode for hardcopy */ 1262.It Dv ECHOCTL 1263/* echo control chars as ^(Char) */ 1264.It Dv ISIG 1265/* enable signals 1266.Dv INTR , 1267.Dv QUIT , 1268.Dv [D]SUSP 1269*/ 1270.It Dv ICANON 1271/* canonicalize input lines */ 1272.It Dv ALTWERASE 1273/* use alternate 1274.Dv WERASE 1275algorithm */ 1276.It Dv IEXTEN 1277/* enable 1278.Dv DISCARD 1279and 1280.Dv LNEXT 1281*/ 1282.It Dv EXTPROC 1283/* external processing */ 1284.It Dv TOSTOP 1285/* stop background jobs from output */ 1286.It Dv FLUSHO 1287/* output being flushed (state) */ 1288.It Dv NOKERNINFO 1289/* no kernel output from 1290.Dv VSTATUS 1291*/ 1292.It Dv PENDIN 1293/* XXX retype pending input (state) */ 1294.It Dv NOFLSH 1295/* don't flush after interrupt */ 1296.El 1297.Pp 1298If 1299.Dv ECHO 1300is set, input characters are echoed back to the terminal. 1301If 1302.Dv ECHO 1303is not set, input characters are not echoed. 1304.Pp 1305If 1306.Dv ECHOE 1307and 1308.Dv ICANON 1309are set, the 1310.Dv ERASE 1311character causes the terminal 1312to erase the last character in the current line from the display, if 1313possible. 1314If there is no character to erase, an implementation may echo 1315an indication that this was the case or do nothing. 1316.Pp 1317If 1318.Dv ECHOK 1319and 1320.Dv ICANON 1321are set, the 1322.Dv KILL 1323character causes 1324the current line to be discarded and the system echoes the 1325.Ql \&\en 1326character after the 1327.Dv KILL 1328character. 1329.Pp 1330If 1331.Dv ECHOKE 1332and 1333.Dv ICANON 1334are set, the 1335.Dv KILL 1336character causes 1337the current line to be discarded and the system causes 1338the terminal 1339to erase the line from the display. 1340.Pp 1341If 1342.Dv ECHOPRT 1343and 1344.Dv ICANON 1345are set, the system assumes 1346that the display is a printing device and prints a 1347backslash and the erased characters when processing 1348.Dv ERASE 1349characters, followed by a forward slash. 1350.Pp 1351If 1352.Dv ECHOCTL 1353is set, the system echoes control characters 1354in a visible fashion using a caret followed by the control character. 1355.Pp 1356If 1357.Dv ALTWERASE 1358is set, the system uses an alternative algorithm 1359for determining what constitutes a word when processing 1360.Dv WERASE 1361characters (see 1362.Dv WERASE ) . 1363.Pp 1364If 1365.Dv ECHONL 1366and 1367.Dv ICANON 1368are set, the 1369.Ql \&\en 1370character echoes even if 1371.Dv ECHO 1372is not set. 1373.Pp 1374If 1375.Dv ICANON 1376is set, canonical processing is enabled. 1377This enables the 1378erase and kill edit functions, and the assembly of input characters into 1379lines delimited by 1380.Dv NL , 1381.Dv EOF , 1382and 1383.Dv EOL , 1384as described in 1385.Sx "Canonical Mode Input Processing" . 1386.Pp 1387If 1388.Dv ICANON 1389is not set, read requests are satisfied directly from the input queue. 1390A read is not satisfied until at least 1391.Dv MIN 1392bytes have been 1393received or the timeout value 1394.Dv TIME 1395expired between bytes. 1396The time value represents tenths of seconds. 1397See 1398.Sx "Noncanonical Mode Input Processing" 1399for more details. 1400.Pp 1401If 1402.Dv ISIG 1403is set, each input character is checked against the special 1404control characters 1405.Dv INTR , 1406.Dv QUIT , 1407and 1408.Dv SUSP 1409(job control only). 1410If an input character matches one of these control characters, the function 1411associated with that character is performed. 1412If 1413.Dv ISIG 1414is not set, no checking is done. 1415Thus these special input functions are possible only if 1416.Dv ISIG 1417is set. 1418.Pp 1419If 1420.Dv IEXTEN 1421is set, implementation-defined functions are recognized from the input data. 1422How 1423.Dv IEXTEN 1424being set 1425interacts with 1426.Dv ICANON , 1427.Dv ISIG , 1428.Dv IXON , 1429or 1430.Dv IXOFF 1431is implementation defined. 1432If 1433.Dv IEXTEN 1434is not set, then 1435implementation-defined functions are not recognized, and the 1436corresponding input characters are not processed as described for 1437.Dv ICANON , 1438.Dv ISIG , 1439.Dv IXON , 1440and 1441.Dv IXOFF . 1442.Pp 1443If 1444.Dv NOFLSH 1445is set, the normal flush of the input and output queues 1446associated with the 1447.Dv INTR , 1448.Dv QUIT , 1449and 1450.Dv SUSP 1451characters 1452are not be done. 1453.Pp 1454If 1455.Dv TOSTOP 1456is set, the signal 1457.Dv SIGTTOU 1458is sent to the process group of a process that tries to write to 1459its controlling terminal if it is not in the foreground process group for 1460that terminal. 1461This signal, by default, stops the members of the process group. 1462Otherwise, the output generated by that process is output to the 1463current output stream. 1464Processes that are blocking or ignoring 1465.Dv SIGTTOU 1466signals are excepted and allowed to produce output and the 1467.Dv SIGTTOU 1468signal 1469is not sent. 1470.Pp 1471If 1472.Dv NOKERNINFO 1473is set, the kernel does not produce a status message 1474when processing 1475.Dv STATUS 1476characters (see 1477.Dv STATUS ) . 1478.Ss Special Control Characters 1479The special control characters values are defined by the array 1480.Fa c_cc . 1481This table lists the array index, the corresponding special character, 1482and the system default value. 1483For an accurate list of the system defaults, consult the header file 1484.In sys/ttydefaults.h . 1485.Pp 1486.Bl -column "Index Name" "Special Character" -offset indent -compact 1487.It Em "Index Name Special Character Default Value" 1488.It Dv VEOF Ta EOF Ta \&^D 1489.It Dv VEOL Ta EOL Ta _POSIX_VDISABLE 1490.It Dv VEOL2 Ta EOL2 Ta _POSIX_VDISABLE 1491.It Dv VERASE Ta ERASE Ta \&^? Ql \&\e177 1492.It Dv VWERASE Ta WERASE Ta \&^W 1493.It Dv VKILL Ta KILL Ta \&^U 1494.It Dv VREPRINT Ta REPRINT Ta \&^R 1495.It Dv VINTR Ta INTR Ta \&^C 1496.It Dv VQUIT Ta QUIT Ta \&^\e\e Ql \&\e34 1497.It Dv VSUSP Ta SUSP Ta \&^Z 1498.It Dv VDSUSP Ta DSUSP Ta \&^Y 1499.It Dv VSTART Ta START Ta \&^Q 1500.It Dv VSTOP Ta STOP Ta \&^S 1501.It Dv VLNEXT Ta LNEXT Ta \&^V 1502.It Dv VDISCARD Ta DISCARD Ta \&^O 1503.It Dv VMIN Ta --- Ta \&1 1504.It Dv VTIME Ta --- Ta \&0 1505.It Dv VSTATUS Ta STATUS Ta \&^T 1506.El 1507.Pp 1508If the 1509value of one of the changeable special control characters (see 1510.Sx "Special Characters" ) 1511is 1512.Dv {_POSIX_VDISABLE} , 1513that function is disabled; that is, no input 1514data is recognized as the disabled special character. 1515If 1516.Dv ICANON 1517is 1518not set, the value of 1519.Dv {_POSIX_VDISABLE} 1520has no special meaning for the 1521.Dv VMIN 1522and 1523.Dv VTIME 1524entries of the 1525.Fa c_cc 1526array. 1527.Pp 1528The initial values of the flags and control characters 1529after 1530.Fn open 1531is set according to 1532the values in the header 1533.In sys/ttydefaults.h . 1534