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