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