]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - share/man/man4/termios.4
Add cdceem(4) driver, for virtual ethernet devices compliant
[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 .It Dv CNO_RTSDTR
1189 /* Do not assert RTS or DTR automatically */
1190 .El
1191 .Pp
1192 The
1193 .Dv CSIZE
1194 bits specify the byte size in bits for both transmission and
1195 reception.
1196 The
1197 .Fa c_cflag
1198 is masked with
1199 .Dv CSIZE
1200 and compared with the
1201 values
1202 .Dv CS5 ,
1203 .Dv CS6 ,
1204 .Dv CS7 ,
1205 or
1206 .Dv CS8 .
1207 This size does not include the parity bit, if any.
1208 If
1209 .Dv CSTOPB
1210 is set, two stop bits are used, otherwise one stop bit.
1211 For example, at 110 baud, two stop bits are normally used.
1212 .Pp
1213 If
1214 .Dv CREAD
1215 is set, the receiver is enabled.
1216 Otherwise, no character is received.
1217 Not all hardware supports this bit.
1218 In fact, this flag is pretty silly and if it were not part of the
1219 .Nm
1220 specification
1221 it would be omitted.
1222 .Pp
1223 If
1224 .Dv PARENB
1225 is set, parity generation and detection are enabled and a parity
1226 bit is added to each character.
1227 If parity is enabled,
1228 .Dv PARODD
1229 specifies
1230 odd parity if set, otherwise even parity is used.
1231 .Pp
1232 If
1233 .Dv HUPCL
1234 is set, the modem control lines for the port are lowered
1235 when the last process with the port open closes the port or the process
1236 terminates.
1237 The modem connection is broken.
1238 .Pp
1239 If
1240 .Dv CLOCAL
1241 is set, a connection does not depend on the state of the modem
1242 status lines.
1243 If
1244 .Dv CLOCAL
1245 is clear, the modem status lines are
1246 monitored.
1247 .Pp
1248 Under normal circumstances, a call to the
1249 .Fn open
1250 function waits for
1251 the modem connection to complete.
1252 However, if the
1253 .Dv O_NONBLOCK
1254 flag is set
1255 or if
1256 .Dv CLOCAL
1257 has been set, the
1258 .Fn open
1259 function returns
1260 immediately without waiting for the connection.
1261 .Pp
1262 The
1263 .Dv CCTS_OFLOW
1264 .Pf ( Dv CRTSCTS )
1265 flag is currently unused.
1266 .Pp
1267 If
1268 .Dv MDMBUF
1269 is set then output flow control is controlled by the state
1270 of Carrier Detect.
1271 .Pp
1272 If
1273 .Dv CNO_RTSDTR
1274 is set then the RTS and DTR lines will not be asserted when the device
1275 is opened.
1276 As a result, this flag is only useful on initial-state devices.
1277 .Pp
1278 If the object for which the control modes are set is not an asynchronous
1279 serial connection, some of the modes may be ignored; for example, if an
1280 attempt is made to set the baud rate on a network connection to a
1281 terminal on another host, the baud rate may or may not be set on the
1282 connection between that terminal and the machine it is directly connected
1283 to.
1284 .Ss Local Modes
1285 Values of the
1286 .Fa c_lflag
1287 field describe the control of
1288 various functions, and are composed of the following
1289 masks.
1290 .Pp
1291 .Bl -tag -width NOKERNINFO -offset indent -compact
1292 .It Dv ECHOKE
1293 /* visual erase for line kill */
1294 .It Dv ECHOE
1295 /* visually erase chars */
1296 .It Dv ECHO
1297 /* enable echoing */
1298 .It Dv ECHONL
1299 /* echo
1300 .Dv NL
1301 even if
1302 .Dv ECHO
1303 is off */
1304 .It Dv ECHOPRT
1305 /* visual erase mode for hardcopy */
1306 .It Dv ECHOCTL
1307 /* echo control chars as ^(Char) */
1308 .It Dv ISIG
1309 /* enable signals
1310 .Dv INTR ,
1311 .Dv QUIT ,
1312 .Dv [D]SUSP
1313 */
1314 .It Dv ICANON
1315 /* canonicalize input lines */
1316 .It Dv ALTWERASE
1317 /* use alternate
1318 .Dv WERASE
1319 algorithm */
1320 .It Dv IEXTEN
1321 /* enable
1322 .Dv DISCARD
1323 and
1324 .Dv LNEXT
1325 */
1326 .It Dv EXTPROC
1327 /* external processing */
1328 .It Dv TOSTOP
1329 /* stop background jobs from output */
1330 .It Dv FLUSHO
1331 /* output being flushed (state) */
1332 .It Dv NOKERNINFO
1333 /* no kernel output from
1334 .Dv VSTATUS
1335 */
1336 .It Dv PENDIN
1337 /* XXX retype pending input (state) */
1338 .It Dv NOFLSH
1339 /* don't flush after interrupt */
1340 .El
1341 .Pp
1342 If
1343 .Dv ECHO
1344 is set, input characters are echoed back to the terminal.
1345 If
1346 .Dv ECHO
1347 is not set, input characters are not echoed.
1348 .Pp
1349 If
1350 .Dv ECHOE
1351 and
1352 .Dv ICANON
1353 are set, the
1354 .Dv ERASE
1355 character causes the terminal
1356 to erase the last character in the current line from the display, if
1357 possible.
1358 If there is no character to erase, an implementation may echo
1359 an indication that this was the case or do nothing.
1360 .Pp
1361 If
1362 .Dv ECHOK
1363 and
1364 .Dv ICANON
1365 are set, the
1366 .Dv KILL
1367 character causes
1368 the current line to be discarded and the system echoes the
1369 .Ql \&\en
1370 character after the
1371 .Dv KILL
1372 character.
1373 .Pp
1374 If
1375 .Dv ECHOKE
1376 and
1377 .Dv ICANON
1378 are set, the
1379 .Dv KILL
1380 character causes
1381 the current line to be discarded and the system causes
1382 the terminal
1383 to erase the line from the display.
1384 .Pp
1385 If
1386 .Dv ECHOPRT
1387 and
1388 .Dv ICANON
1389 are set, the system assumes
1390 that the display is a printing device and prints a
1391 backslash and the erased characters when processing
1392 .Dv ERASE
1393 characters, followed by a forward slash.
1394 .Pp
1395 If
1396 .Dv ECHOCTL
1397 is set, the system echoes control characters
1398 in a visible fashion using a caret followed by the control character.
1399 .Pp
1400 If
1401 .Dv ALTWERASE
1402 is set, the system uses an alternative algorithm
1403 for determining what constitutes a word when processing
1404 .Dv WERASE
1405 characters (see
1406 .Dv WERASE ) .
1407 .Pp
1408 If
1409 .Dv ECHONL
1410 and
1411 .Dv ICANON
1412 are set, the
1413 .Ql \&\en
1414 character echoes even if
1415 .Dv ECHO
1416 is not set.
1417 .Pp
1418 If
1419 .Dv ICANON
1420 is set, canonical processing is enabled.
1421 This enables the
1422 erase and kill edit functions, and the assembly of input characters into
1423 lines delimited by
1424 .Dv NL ,
1425 .Dv EOF ,
1426 and
1427 .Dv EOL ,
1428 as described in
1429 .Sx "Canonical Mode Input Processing" .
1430 .Pp
1431 If
1432 .Dv ICANON
1433 is not set, read requests are satisfied directly from the input
1434 queue.
1435 A read is not satisfied until at least
1436 .Dv MIN
1437 bytes have been
1438 received or the timeout value
1439 .Dv TIME
1440 expired between bytes.
1441 The time value
1442 represents tenths of seconds.
1443 See
1444 .Sx "Noncanonical Mode Input Processing"
1445 for more details.
1446 .Pp
1447 If
1448 .Dv ISIG
1449 is set, each input character is checked against the special
1450 control characters
1451 .Dv INTR ,
1452 .Dv QUIT ,
1453 and
1454 .Dv SUSP
1455 (job control only).
1456 If an input
1457 character matches one of these control characters, the function
1458 associated with that character is performed.
1459 If
1460 .Dv ISIG
1461 is not set, no
1462 checking is done.
1463 Thus these special input functions are possible only
1464 if
1465 .Dv ISIG
1466 is set.
1467 .Pp
1468 If
1469 .Dv IEXTEN
1470 is set, implementation-defined functions are recognized
1471 from the input data.
1472 How
1473 .Dv IEXTEN
1474 being set
1475 interacts with
1476 .Dv ICANON ,
1477 .Dv ISIG ,
1478 .Dv IXON ,
1479 or
1480 .Dv IXOFF
1481 is implementation defined.
1482 If
1483 .Dv IEXTEN
1484 is not set, then
1485 implementation-defined functions are not recognized, and the
1486 corresponding input characters are not processed as described for
1487 .Dv ICANON ,
1488 .Dv ISIG ,
1489 .Dv IXON ,
1490 and
1491 .Dv IXOFF .
1492 .Pp
1493 If
1494 .Dv NOFLSH
1495 is set, the normal flush of the input and output queues
1496 associated with the
1497 .Dv INTR ,
1498 .Dv QUIT ,
1499 and
1500 .Dv SUSP
1501 characters
1502 are not be done.
1503 .Pp
1504 If
1505 .Dv TOSTOP
1506 is set, the signal
1507 .Dv SIGTTOU
1508 is sent to the process group of a process that tries to write to
1509 its controlling terminal if it is not in the foreground process group for
1510 that terminal.
1511 This signal, by default, stops the members of the process group.
1512 Otherwise, the output generated by that process is output to the
1513 current output stream.
1514 Processes that are blocking or ignoring
1515 .Dv SIGTTOU
1516 signals are excepted and allowed to produce output and the
1517 .Dv SIGTTOU
1518 signal
1519 is not sent.
1520 .Pp
1521 If
1522 .Dv NOKERNINFO
1523 is set, the kernel does not produce a status message
1524 when processing
1525 .Dv STATUS
1526 characters (see
1527 .Dv STATUS ) .
1528 .Ss Special Control Characters
1529 The special control characters values are defined by the array
1530 .Fa c_cc .
1531 This table lists the array index, the corresponding special character,
1532 and the system default value.
1533 For an accurate list of
1534 the system defaults, consult the header file
1535 .In sys/ttydefaults.h .
1536 .Pp
1537 .Bl -column "Index Name" "Special Character" -offset indent -compact
1538 .It Em "Index Name      Special Character       Default Value"
1539 .It Dv VEOF Ta EOF Ta \&^D
1540 .It Dv VEOL Ta EOL Ta _POSIX_VDISABLE
1541 .It Dv VEOL2 Ta EOL2 Ta _POSIX_VDISABLE
1542 .It Dv VERASE Ta ERASE Ta \&^? Ql \&\e177
1543 .It Dv VWERASE Ta WERASE Ta \&^W
1544 .It Dv VKILL Ta KILL Ta \&^U
1545 .It Dv VREPRINT Ta REPRINT Ta \&^R
1546 .It Dv VINTR Ta INTR Ta \&^C
1547 .It Dv VQUIT Ta QUIT Ta \&^\e\e Ql \&\e34
1548 .It Dv VSUSP Ta SUSP Ta \&^Z
1549 .It Dv VDSUSP Ta DSUSP Ta \&^Y
1550 .It Dv VSTART Ta START Ta \&^Q
1551 .It Dv VSTOP Ta STOP Ta \&^S
1552 .It Dv VLNEXT Ta LNEXT Ta \&^V
1553 .It Dv VDISCARD Ta DISCARD Ta \&^O
1554 .It Dv VMIN Ta --- Ta \&1
1555 .It Dv VTIME Ta --- Ta \&0
1556 .It Dv VSTATUS Ta STATUS Ta \&^T
1557 .El
1558 .Pp
1559 If the
1560 value of one of the changeable special control characters (see
1561 .Sx "Special Characters" )
1562 is
1563 .Dv {_POSIX_VDISABLE} ,
1564 that function is disabled; that is, no input
1565 data is recognized as the disabled special character.
1566 If
1567 .Dv ICANON
1568 is
1569 not set, the value of
1570 .Dv {_POSIX_VDISABLE}
1571 has no special meaning for the
1572 .Dv VMIN
1573 and
1574 .Dv VTIME
1575 entries of the
1576 .Fa c_cc
1577 array.
1578 .Pp
1579 The initial values of the flags and control characters
1580 after
1581 .Fn open
1582 is set according to
1583 the values in the header
1584 .In sys/ttydefaults.h .
1585 .Sh SEE ALSO
1586 .Xr stty 1 ,
1587 .Xr tcgetsid 3 ,
1588 .Xr tcsendbreak 3 ,
1589 .Xr tcsetattr 3 ,
1590 .Xr tcsetsid 3 ,
1591 .Xr tty 4