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