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