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.Dd January 14, 2026 29.Dt TERMIOS 4 30.Os 31.Sh NAME 32.Nm termios 33.Nd general terminal line discipline 34.Sh SYNOPSIS 35.In termios.h 36.Sh DESCRIPTION 37This describes a general terminal line discipline that is 38supported on tty asynchronous communication ports. 39.Ss Opening a Terminal Device File 40When a terminal file is opened, it normally causes the process to wait 41until a connection is established. 42For most hardware, the presence 43of a connection is indicated by the assertion of the hardware 44.Dv CARRIER 45line. 46If the termios structure associated with the terminal file has the 47.Dv CLOCAL 48flag set in the cflag, or if the 49.Dv O_NONBLOCK 50flag is set 51in the 52.Xr open 2 53call, then the open will succeed even without 54a connection being present. 55In practice, applications 56seldom open these files; they are opened by special programs, such 57as 58.Xr getty 8 , 59and become 60an application's standard input, output, and error files. 61.Ss Job Control in a Nutshell 62Every process is associated with a particular process group and session. 63The grouping is hierarchical: every member of a particular process group is a 64member of the same session. 65This structuring is used in managing groups 66of related processes for purposes of 67.\" .Gw "job control" ; 68.Em "job control" ; 69that is, the 70ability from the keyboard (or from program control) to simultaneously 71stop or restart 72a complex command (a command composed of one or more related 73processes). 74The grouping into process groups allows delivering 75of signals that stop or start the group as a whole, along with 76arbitrating which process group has access to the single controlling 77terminal. 78The grouping at a higher layer into sessions is to restrict 79the job control related signals and system calls to within processes 80resulting from a particular instance of a 81.Dq login . 82Typically, a session 83is created when a user logs in, and the login terminal is setup 84to be the controlling terminal; all processes spawned from that 85login shell are in the same session, and inherit the controlling 86terminal. 87.Pp 88A job control shell 89operating interactively (that is, reading commands from a terminal) 90normally groups related processes together by placing them into the 91same process group. 92A set of processes in the same process group 93is collectively referred to as a 94.Dq job . 95When the foreground process 96group of the terminal is the same as the process group of a particular 97job, that job is said to be in the 98.Dq foreground . 99When the process group 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 102.Dq background . 103Normally the 104shell reads a command and starts the job that implements that 105command. 106If the command is to be started in the foreground (typical), it 107sets the process group of the terminal to the process group 108of the started job, waits for the job to complete, and then 109sets the process group of the terminal back to its own process 110group (it puts itself into the foreground). 111If the job is to 112be started in the background (as denoted by the shell operator "&"), 113it never changes the process group of the terminal and does not 114wait for the job to complete (that is, it immediately attempts to read the next 115command). 116If the job is started in the foreground, the user may 117type a key (usually 118.Ql \&^Z ) 119which generates the terminal stop signal 120.Pq Dv SIGTSTP 121and has the effect of stopping the entire job. 122The shell will notice that the job stopped, and will resume running after 123placing itself in the foreground. 124The shell also has commands for placing stopped jobs in the background, 125and for placing stopped or background jobs into the foreground. 126.Ss Orphaned Process Groups 127An orphaned process group is a process group that has no process 128whose parent is in a different process group, yet is in the same 129session. 130Conceptually it means a process group that does not have 131a parent that could do anything if it were to be stopped. 132For example, 133the initial login shell is typically in an orphaned process group. 134Orphaned process groups are immune to keyboard generated stop 135signals and job control signals resulting from reads or writes to the 136controlling terminal. 137.Ss The Controlling Terminal 138A terminal may belong to a process as its controlling terminal. 139Each 140process of a session that has a controlling terminal has the same 141controlling terminal. 142A terminal may be the controlling terminal for at 143most one session. 144The controlling terminal for a session is allocated by 145the session leader by issuing the 146.Dv TIOCSCTTY 147ioctl. 148A controlling terminal 149is never acquired by merely opening a terminal device file. 150When a controlling terminal becomes 151associated with a session, its foreground process group is set to 152the process group of the session leader. 153.Pp 154The controlling terminal is inherited by a child process during a 155.Xr fork 2 156function call. 157A process relinquishes its controlling terminal when it 158creates a new session with the 159.Xr setsid 2 160function; other processes 161remaining in the old session that had this terminal as their controlling 162terminal continue to have it. 163A process does not relinquish its 164controlling terminal simply by closing all of its file descriptors 165associated with the controlling terminal if other processes continue to 166have it open. 167.Pp 168When a controlling process terminates, the controlling terminal is 169disassociated from the current session, allowing it to be acquired by a 170new session leader. 171Subsequent access to the terminal by other processes 172in the earlier session will be denied, with attempts to access the 173terminal treated as if modem disconnect had been sensed. 174.Ss Terminal Access Control 175If a process is in the foreground process group of its controlling 176terminal, read operations are allowed. 177Any attempts by a process 178in a background process group to read from its controlling terminal 179causes a 180.Dv SIGTTIN 181signal to be sent to 182the process's group 183unless one of the 184following special cases apply: if the reading process is ignoring or 185blocking the 186.Dv SIGTTIN 187signal, or if the process group of the reading 188process is orphaned, the 189.Xr read 2 190returns -1 with 191.Va errno 192set to 193.Er EIO 194and no 195signal is sent. 196The default action of the 197.Dv SIGTTIN 198signal is to stop the 199process to which it is sent. 200.Pp 201If a process is in the foreground process group of its controlling 202terminal, write operations are allowed. 203Attempts by a process in a background process group to write to its 204controlling terminal will cause the process group to be sent a 205.Dv SIGTTOU 206signal unless one of the following special cases apply: if 207.Dv TOSTOP 208is not 209set, or if 210.Dv TOSTOP 211is set and the process is ignoring or blocking the 212.Dv SIGTTOU 213signal, the process is allowed to write to the terminal and the 214.Dv SIGTTOU 215signal is not sent. 216If 217.Dv TOSTOP 218is set, and the process group of 219the writing process is orphaned, and the writing process is not ignoring 220or blocking 221.Dv SIGTTOU , 222the 223.Xr write 2 224returns -1 with 225errno set to 226.Er EIO 227and no signal is sent. 228.Pp 229Certain calls that set terminal parameters are treated in the same 230fashion as write, except that 231.Dv TOSTOP 232is ignored; that is, the effect is 233identical to that of terminal writes when 234.Dv TOSTOP 235is set. 236.Ss Input Processing and Reading Data 237A terminal device associated with a terminal device file may operate in 238full-duplex mode, so that data may arrive even while output is occurring. 239Each terminal device file has associated with it an input queue, into 240which incoming data is stored by the system before being read by a 241process. 242The system imposes a limit, 243.Pf \&{ Dv MAX_INPUT Ns \&} , 244on the number of 245bytes that may be stored in the input queue. 246The behavior of the system 247when this limit is exceeded depends on the setting of the 248.Dv IMAXBEL 249flag in the termios 250.Fa c_iflag . 251If this flag is set, the terminal 252is sent an 253.Tn ASCII 254.Dv BEL 255character each time a character is received 256while the input queue is full. 257Otherwise, the input queue is flushed upon receiving the character. 258.Pp 259Two general kinds of input processing are available, determined by 260whether the terminal device file is in canonical mode or noncanonical 261mode. 262Additionally, 263input characters are processed according to the 264.Fa c_iflag 265and 266.Fa c_lflag 267fields. 268Such processing can include echoing, which 269in general means transmitting input characters immediately back to the 270terminal when they are received from the terminal. 271This is useful for terminals that can operate in full-duplex mode. 272.Pp 273The manner in which data is provided to a process reading from a terminal 274device file is dependent on whether the terminal device file is in 275canonical or noncanonical mode. 276.Pp 277Another dependency is whether the 278.Dv O_NONBLOCK 279flag is set by 280.Xr open 2 281or 282.Xr fcntl 2 . 283If the 284.Dv O_NONBLOCK 285flag is clear, then the read request is 286blocked until data is available or a signal has been received. 287If the 288.Dv O_NONBLOCK 289flag is set, then the read request is completed, without 290blocking, in one of three ways: 291.Bl -enum -offset indent 292.It 293If there is enough data available to satisfy the entire request, 294and the read completes successfully the number of 295bytes read is returned. 296.It 297If there is not enough data available to satisfy the entire 298request, and the read completes successfully, having read as 299much data as possible, the number of bytes read is returned. 300.It 301If there is no data available, the read returns -1, with 302errno set to 303.Er EAGAIN . 304.El 305.Pp 306When data is available depends on whether the input processing mode is 307canonical or noncanonical. 308.Ss Canonical Mode Input Processing 309In canonical mode input processing, terminal input is processed in units 310of lines. 311A line is delimited by a newline 312.Ql \&\en 313character, an end-of-file 314.Pq Dv EOF 315character, or an end-of-line 316.Pq Dv EOL 317character. 318See the 319.Sx "Special Characters" 320section for 321more information on 322.Dv EOF 323and 324.Dv EOL . 325This means that a read request will 326not return until an entire line has been typed, or a signal has been 327received. 328Also, no matter how many bytes are requested in the read call, 329at most one line is returned. 330It is not, however, necessary to 331read a whole line at once; any number of bytes, even one, may be 332requested in a read without losing information. 333.Pp 334.Pf \&{ Dv MAX_CANON Ns \&} 335is a limit on the 336number of bytes in a line. 337The behavior of the system when this limit is 338exceeded is the same as when the input queue limit 339.Pf \&{ Dv MAX_INPUT Ns \&} , 340is exceeded. 341.Pp 342Erase and kill processing occur when either of two special characters, 343the 344.Dv ERASE 345and 346.Dv KILL 347characters (see the 348.Sx "Special Characters" 349section), is received. 350This processing affects data in the input queue that has not yet been 351delimited by a newline 352.Dv NL , 353.Dv EOF , 354or 355.Dv EOL 356character. 357This un-delimited 358data makes up the current line. 359The 360.Dv ERASE 361character deletes the last 362character in the current line, if there is any. 363The 364.Dv KILL 365character 366deletes all data in the current line, if there is any. 367The 368.Dv ERASE 369and 370.Dv KILL 371characters have no effect if there is no data in the current line. 372The 373.Dv ERASE 374and 375.Dv KILL 376characters themselves are not placed in the input 377queue. 378.Ss Noncanonical Mode Input Processing 379In noncanonical mode input processing, input bytes are not assembled into 380lines, and erase and kill processing does not occur. 381The values of the 382.Dv VMIN 383and 384.Dv VTIME 385members of the 386.Fa c_cc 387array are used to determine how to 388process the bytes received. 389.Pp 390.Dv MIN 391represents the minimum number of bytes that should be received when 392the 393.Xr read 2 394function successfully returns. 395.Dv TIME 396is a timer of 0.1 second 397granularity that is used to time out bursty and short term data 398transmissions. 399If 400.Dv MIN 401is greater than 402.Dv \&{ Dv MAX_INPUT Ns \&} , 403the response to the 404request is undefined. 405The four possible values for 406.Dv MIN 407and 408.Dv TIME 409and 410their interactions are described below. 411.Ss "Case A: MIN > 0, TIME > 0" 412In this case 413.Dv TIME 414serves as an inter-byte timer and is activated after 415the first byte is received. 416Since it is an inter-byte timer, it is reset 417after a byte is received. 418The interaction between 419.Dv MIN 420and 421.Dv TIME 422is as 423follows: as soon as one byte is received, the inter-byte timer is 424started. 425If 426.Dv MIN 427bytes are received before the inter-byte timer expires 428(remember that the timer is reset upon receipt of each byte), the read is 429satisfied. 430If the timer expires before 431.Dv MIN 432bytes are received, the 433characters received to that point are returned to the user. 434Note that if 435.Dv TIME 436expires at least one byte is returned because the timer would 437not have been enabled unless a byte was received. 438In this case 439.Pf \&( Dv MIN 440> 0, 441.Dv TIME 442> 0) the read blocks until the 443.Dv MIN 444and 445.Dv TIME 446mechanisms are 447activated by the receipt of the first byte, or a signal is received. 448If data is in the buffer at the time of the 449.Fn read , 450the result is as 451if data had been received immediately after the 452.Fn read . 453.Ss "Case B: MIN > 0, TIME = 0" 454In this case, since the value of 455.Dv TIME 456is zero, the timer plays no role 457and only 458.Dv MIN 459is significant. 460A pending read is not satisfied until 461.Dv MIN 462bytes are received (i.e., the pending read blocks until 463.Dv MIN 464bytes 465are received), or a signal is received. 466A program that uses this case to read record-based terminal 467.Dv I/O 468may block indefinitely in the read 469operation. 470.Ss "Case C: MIN = 0, TIME > 0" 471In this case, since 472.Dv MIN 473= 0, 474.Dv TIME 475no longer represents an inter-byte 476timer. 477It now serves as a read timer that is activated as soon as the 478read function is processed. 479A read is satisfied as soon as a single 480byte is received or the read timer expires. 481Note that in this case if the timer expires, no bytes are returned. 482If the timer does not 483expire, the only way the read can be satisfied is if a byte is received. 484In this case the read will not block indefinitely waiting for a byte; if 485no byte is received within 486.Dv TIME Ns *0.1 487seconds after the read is initiated, 488the read returns a value of zero, having read no data. 489If data is 490in the buffer at the time of the read, the timer is started as if 491data had been received immediately after the read. 492.Ss Case D: MIN = 0, TIME = 0 493The minimum of either the number of bytes requested or the number of 494bytes currently available is returned without waiting for more 495bytes to be input. 496If no characters are available, read returns a 497value of zero, having read no data. 498.Ss Writing Data and Output Processing 499When a process writes one or more bytes to a terminal device file, they 500are processed according to the 501.Fa c_oflag 502field (see the 503.Sx "Output Modes" 504section). 505The 506implementation may provide a buffering mechanism; as such, when a call to 507.Fn write 508completes, all of the bytes written have been scheduled for 509transmission to the device, but the transmission will not necessarily 510have been completed. 511.\" See also .Sx "6.4.2" for the effects of 512.\" .Dv O_NONBLOCK 513.\" on write. 514.Ss Special Characters 515Certain characters have special functions on input or output or both. 516These functions are summarized as follows: 517.Bl -tag -width indent 518.It Dv INTR 519Special character on input and is recognized if the 520.Dv ISIG 521flag (see the 522.Sx "Local Modes" 523section) is enabled. 524Generates a 525.Dv SIGINT 526signal which is sent to all processes in the foreground 527process group for which the terminal is the controlling 528terminal. 529If 530.Dv ISIG 531is set, the 532.Dv INTR 533character is 534discarded when processed. 535.It Dv QUIT 536Special character on input and is recognized if the 537.Dv ISIG 538flag is enabled. 539Generates a 540.Dv SIGQUIT 541signal which is 542sent to all processes in the foreground process group 543for which the terminal is the controlling terminal. 544If 545.Dv ISIG 546is set, the 547.Dv QUIT 548character is discarded when 549processed. 550.It Dv ERASE 551Special character on input and is recognized if the 552.Dv ICANON 553flag is set. 554Erases the last character in the 555current line; see 556.Sx "Canonical Mode Input Processing" . 557It does not erase beyond 558the start of a line, as delimited by an 559.Dv NL , 560.Dv EOF , 561or 562.Dv EOL 563character. 564If 565.Dv ICANON 566is set, the 567.Dv ERASE 568character is 569discarded when processed. 570.It Dv KILL 571Special character on input and is recognized if the 572.Dv ICANON 573flag is set. 574Deletes the entire line, as 575delimited by a 576.Dv NL , 577.Dv EOF , 578or 579.Dv EOL 580character. 581If 582.Dv ICANON 583is set, the 584.Dv KILL 585character is discarded when processed. 586.It Dv EOF 587Special character on input and is recognized if the 588.Dv ICANON 589flag is set. 590When received, all the bytes 591waiting to be read are immediately passed to the 592process, without waiting for a newline, and the 593.Dv EOF 594is discarded. 595Thus, if there are no bytes waiting (that is, the 596.Dv EOF 597occurred at the beginning of a line), a byte 598count of zero is returned from the 599.Fn read , 600representing an end-of-file indication. 601If 602.Dv ICANON 603is 604set, the 605.Dv EOF 606character is discarded when processed. 607.It Dv NL 608Special character on input and is recognized if the 609.Dv ICANON 610flag is set. 611It is the line delimiter 612.Ql \&\en . 613.It Dv EOL 614Special character on input and is recognized if the 615.Dv ICANON 616flag is set. 617Is an additional line delimiter, like 618.Dv NL . 619.It Dv SUSP 620If the 621.Dv ISIG 622flag is enabled, receipt of the 623.Dv SUSP 624character causes a 625.Dv SIGTSTP 626signal to be sent to all processes in the 627foreground process group for which the terminal is the 628controlling terminal, and the 629.Dv SUSP 630character is 631discarded when processed. 632.It Dv STOP 633Special character on both input and output and is 634recognized if the 635.Dv IXON 636(output control) or 637.Dv IXOFF 638(input 639control) flag is set. 640Can be used to temporarily suspend output. 641It is useful with fast terminals to 642prevent output from disappearing before it can be read. 643If 644.Dv IXON 645is set, the 646.Dv STOP 647character is discarded when 648processed. 649.It Dv START 650Special character on both input and output and is 651recognized if the 652.Dv IXON 653(output control) or 654.Dv IXOFF 655(input 656control) flag is set. 657Can be used to resume output that has been suspended by a 658.Dv STOP 659character. 660If 661.Dv IXON 662is set, the 663.Dv START 664character is discarded when processed. 665.It Dv CR 666Special character on input and is recognized if the 667.Dv ICANON 668flag is set; it is the 669.Ql \&\er , 670as denoted in the 671.Tn \&C 672Standard {2}. 673When 674.Dv ICANON 675and 676.Dv ICRNL 677are set and 678.Dv IGNCR 679is not set, this character is translated into a 680.Dv NL , 681and 682has the same effect as a 683.Dv NL 684character. 685.El 686.Pp 687The following special characters are extensions defined by this 688system and are not a part of 689.St -p1003.1 690termios. 691.Bl -tag -width indent 692.It Dv EOL2 693Secondary 694.Dv EOL 695character. 696Same function as 697.Dv EOL . 698.It Dv WERASE 699Special character on input and is recognized if the 700.Dv ICANON 701flag is set. 702Erases the last word in the current line according to one of two algorithms. 703If the 704.Dv ALTWERASE 705flag is not set, first any preceding whitespace is 706erased, and then the maximal sequence of non-whitespace 707characters. 708If 709.Dv ALTWERASE 710is set, first any preceding 711whitespace is erased, and then the maximal sequence 712of alphabetic/underscores or non alphabetic/underscores. 713As a special case in this second algorithm, the first previous 714non-whitespace character is skipped in determining 715whether the preceding word is a sequence of 716alphabetic/underscores. 717This sounds confusing but turns out to be quite practical. 718.It Dv REPRINT 719Special character on input and is recognized if the 720.Dv ICANON 721flag is set. 722Causes the current input edit line to be retyped. 723.It Dv DSUSP 724Has similar actions to the 725.Dv SUSP 726character, except that 727the 728.Dv SIGTSTP 729signal is delivered when one of the processes 730in the foreground process group issues a 731.Fn read 732to the 733controlling terminal. 734.It Dv LNEXT 735Special character on input and is recognized if the 736.Dv IEXTEN 737flag is set. 738Receipt of this character causes the next character to be taken literally. 739.It Dv DISCARD 740Special character on input and is recognized if the 741.Dv IEXTEN 742flag is set. 743Receipt of this character toggles the flushing of terminal output. 744.It Dv STATUS 745Special character on input and is recognized if the 746.Dv ICANON 747flag is set. 748Receipt of this character causes a 749.Dv SIGINFO 750signal to be sent to the foreground process group of the 751terminal. 752Also, if the 753.Dv NOKERNINFO 754flag is not set, it 755causes the kernel to write a status message to the terminal 756that displays the current load average, the name of the 757command in the foreground, its process ID, the symbolic 758wait channel, the number of user and system seconds used, 759the percentage of cpu the process is getting, and the resident 760set size of the process. 761.Pp 762In case the kernel has 763.Xr stack 9 764support configured and 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 uart 4 , 1600.Xr stack 9 1601.Sh BUGS 1602Before the Internet, serial ports were primarily used for inbound 1603connections from terminals, either directly or through modems, these 1604days serial ports are primarily used for outbound connections to 1605devices, an evolution which unfortunately has spread the relevant 1606documentation over three different manual pages: 1607.Xr termios 4 , 1608.Xr uart 4 and 1609.Xr tty 4 . 1610 1611