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