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