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