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