source: trunk/minix/man/man4/tty.4@ 12

Last change on this file since 12 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 18.8 KB
Line 
1.TH TTY 4
2.SH NAME
3tty, termios \- terminals
4.SH DESCRIPTION
5The
6.B tty
7driver family takes care of all user input and output. It governs the
8keyboard, the console, the serial lines, and pseudo ttys. Input on any of
9these devices undergoes "input processing", and output undergoes "output
10processing" according to the standard termios terminal interface.
11.SS "Input processing"
12Each terminal device has an input queue. This queue is used to store
13preprocessed input characters, and to perform the backspacing and erase
14functions. Some special characters like a newline make the contents of the
15queue available to a process reading from the terminal. Characters up to
16and including the newline, or another so-called "line break", may be read by
17a process. The process need not read all characters at once. An input line
18may be read byte by byte if one wants to. A line break just makes
19characters available for reading, thats all.
20.PP
21When data is made available depends on whether the tty is in canonical mode
22or not. In canonical mode the terminal processes input line by line. A
23line ends with a newline
24.RB ( NL ),
25end-of-file
26.RB ( EOF ),
27or end-of-line
28.RB ( EOL ).
29Characters that have not been delimited by such a line break may be erased
30one by one with the
31.B ERASE
32character or all at once with the
33.B KILL
34character. Once a line break is typed the characters become available to a
35reading process and can no longer be erased. Once read they are removed
36from the input queue. Several lines may be gathered in the input queue if
37no reader is present to read them, but a new reader will only receive one
38line. Two line breaks are never returned in one read call. The input queue
39has a maximum length of
40.B MAX_CANON
41characters. Any more characters are discarded. One must use
42.B ERASE
43or
44.B KILL
45to make the terminal functioning again if the input queue fills up. If
46nonblocking I/O is set then \-1 is returned with
47.B errno
48set to
49.B EAGAIN
50if the reader would otherwise be blocked.
51.PP
52In non-canonical mode (raw mode for short) all characters are immediately
53available to the reader in principle. One may however tune the terminal to
54bursty input with the
55.B MIN
56and
57.B TIME
58parameters, see the raw I/O parameters section below. In raw mode no
59characters are discarded if the input queue threatens to overflow if the
60device supports flow control.
61.SS "Output processing"
62Characters written to a terminal device may undergo output processing, which
63is usually just inserting a carriage returns before newlines. A writer
64may return before all characters are output if the characters can be stored
65in the output buffers. If not then the writer may be blocked until space is
66available. If non-blocking I/O is set then only the count of the number of
67bytes that can be processed immediately is returned. If no characters can
68be written at all then \-1 is returned with
69.B errno
70set to
71.BR EAGAIN .
72.SS "Special characters"
73Some characters have special functions in some of the terminal modes. These
74characters are as follows, with the MINIX 3 defaults shown in parentheses:
75.TP 5
76.BR INTR " (^?)"
77Special input character that is recognized if
78.B ISIG
79is set. (For
80.B ISIG
81and other flags see the various modes sections below.) It causes a
82.B SIGINT
83signal to be sent to all processes in the terminal process group. (See the
84section on session leaders below.)
85.TP
86.BR QUIT " (^\e)"
87Special input character if
88.B ISIG
89is set. Causes a
90.B SIGQUIT
91signal to be sent to the terminal process group.
92.TP
93.BR ERASE " (^H)"
94Special input character if
95.B ICANON
96is set. Erases the last character in the current line.
97.TP
98.BR KILL " (^U)"
99Special input character if
100.B ICANON
101is set. Erases the entire line.
102.TP
103.BR EOF " (^D)"
104Special input character if
105.B ICANON
106is set. It is a line break character that is not itself returned to a
107reader. If EOF is typed with no input present then the read returns zero,
108which normally causes the reader to assume that end-of-file is reached.
109.TP
110.BR CR " (^M)"
111Special input character if
112.B IGNCR
113or
114.B ICRNL
115is set. It is a carriage return ('\er'). If
116.B IGNCR
117is set then
118.B CR
119is discarded. If
120.B ICRNL
121is set and
122.B IGNCR
123is not set then
124.B CR
125is changed into an
126.B NL
127and has the same function as
128.BR NL.
129.TP
130.BR NL " (^J)"
131Special input character if
132.B ICANON
133is set. It is both a newline ('\en') and a line break.
134.br
135Special output character if
136.B OPOST
137and
138.B ONLCR
139are set. A
140.B CR NL
141sequence is output instead of just
142.BR NL .
143(MINIX 3 specific, but almost mandatory on any UNIX-like system.)
144.TP
145.BR TAB " (^I)"
146Special character on output if
147.B OPOST
148and
149.B XTABS
150are set. It is transformed into the number of spaces necessary to reach a
151column position that is a multiple of eight. (Only needed for terminals
152without hardware tabs.)
153.TP
154.BR EOL " (undefined)"
155Special input character if
156.B ICANON
157is set. It is an additional line break.
158.TP
159.BR SUSP " (^Z)"
160Special input character if job control is implemented and
161.B ISIG
162is set. It causes a
163.B SIGTSTP
164signal to be send to the terminal process group. (MINIX 3 does not have job
165control.)
166.TP
167.BR STOP " (^S)"
168Special input character if
169.B IXON
170is set. It suspends terminal output and is then discarded.
171.TP
172.BR START " (^Q)"
173Special output character if
174.B IXON
175is set. It starts terminal output if suspended and is then discarded. If
176.B IXANY
177is also set then any other character also starts terminal output, but they
178are not discarded.
179.TP
180.BR REPRINT " (^R)"
181Special input character if
182.B IEXTEN
183and
184.B ECHO
185are set. Reprints the input queue from the last line break onwards. A
186reprint also happens automatically if the echoed input has been messed up by
187other output and
188.B ERASE
189is typed.
190.TP
191.BR LNEXT " (^V)"
192Special input character if
193.B IEXTEN
194is set. It is the "literal next" character that causes the next character
195to be input without any special processing.
196.TP
197.BR DISCARD " (^O)"
198Special input character if
199.B IEXTEN
200is set. Causes output to be discarded until it is typed again. (Implemented
201only under Minix-vmd.)
202.PP
203All of these characters except
204.BR CR ,
205.B NL
206and
207.B TAB
208may be changed or disabled under MINIX 3. (Changes to
209.B START
210and
211.B STOP
212may be ignored under other termios implementations.) The
213.B REPRINT
214and
215.B LNEXT
216characters are MINIX 3 extensions that are commonly present in other
217implementations. \s-2POSIX\s+2 is unclear on whether
218.BR IEXTEN,
219.BR IGNCR
220and
221.BR ICRNL
222should be active in non-canonical mode, but under MINIX 3 they are.
223.SS "Terminal attributes"
224The attributes of a terminal, such as whether the mode should be canonical or
225non-canonical, are controlled by routines that use the
226.B termios
227structure as defined in
228.BR <termios.h> :
229.PP
230.RS
231.nf
232.ta +4n +10n +15n
233struct termios {
234 tcflag_t c_iflag; /* input modes */
235 tcflag_t c_oflag; /* output modes */
236 tcflag_t c_cflag; /* control modes */
237 tcflag_t c_lflag; /* local modes */
238 speed_t c_ispeed; /* input speed */
239 speed_t c_ospeed; /* output speed */
240 cc_t c_cc[NCCS]; /* control characters */
241};
242.fi
243.RE
244.PP
245The types
246.BR tcflag ,
247.B speed_t
248and
249.B cc_t
250are defined in
251.B <termios.h>
252as unsigned integral types.
253.SS "Input Modes"
254The
255.B c_iflag
256field contains the following single bit flags that control input processing:
257.TP 5
258.B ICRNL
259Map
260.B CR
261to
262.B NL
263on input.
264.TP
265.B IGNCR
266Ignore
267.B CR
268on input. This flag overrides
269.BR ICRNL .
270.TP
271.B INLCR
272Map
273.B NL
274to
275.B CR
276on input. This is done after the
277.B IGNCR
278check.
279.TP
280.B IXON
281Enable start/stop output control.
282.TP
283.B IXOFF
284Enable start/stop input control. (Not implemented.)
285.TP
286.B IXANY
287Allow any character to restart output. (MINIX 3 specific.)
288.TP
289.B ISTRIP
290Strip characters to seven bits.
291.TP
292.B IGNPAR
293Ignore characters with parity errors. (Not implemented.)
294.TP
295.B INPCK
296Enable input parity checking. (Not implemented.)
297.TP
298.B PARMRK
299Mark parity errors by preceding the faulty character with '\e377', '\e0'.
300The character '\e377' is preceded by another '\e377' to avoid ambiguity.
301(Not implemented.)
302.TP
303.B BRKINT
304Send the signal
305.B SIGINT
306to the terminal process group when receiving a break condition. (Not
307implemented.)
308.TP
309.B IGNBRK
310Ignore break condition. If neither
311.B BRKINT
312or
313.B IGNBRK
314is set a break is input as a single '\e0', or if
315.B PARMRK
316is set as '\e377', '\e0', '\e0'.
317(Breaks are always ignored.)
318.SS "Output Modes"
319The
320.B c_oflag
321field contains the following single bit flags that control output processing:
322.TP
323.B OPOST
324Perform output processing. This flag is the "main switch" on output
325processing. All other flags are MINIX 3 specific.
326.TP
327.B ONLCR
328Transform an
329.B NL
330to a
331.B CR NL
332sequence on output. Note that a key labeled "RETURN" or "ENTER" usually
333sends a
334.BR CR .
335In line oriented mode this is normally transformed into
336.B NL
337by
338.BR ICRNL .
339.B NL
340is the normal UNIX line delimiter ('\en'). On output an
341.B NL
342is transformed into the
343.B CR NL
344sequence that is necessary to reach the first column of the next line.
345(This is a common output processing function for UNIX-like systems, but not
346always separately switchable by an
347.B ONLCR
348flag.)
349.TP
350.B XTABS
351Transform a
352.B TAB
353into the number of spaces necessary to reach a column position that is a
354multiple of eight.
355.TP
356.B ONOEOT
357Discard
358.B EOT
359(^D) characters. (Minix-vmd only.)
360.SS "Control Modes"
361The
362.B c_cflag
363field contains the following single bit flags and bit field for basic
364hardware control:
365.TP
366.B CLOCAL
367Ignore modem status lines.
368.TP
369.B CREAD
370Enable receiver. (The receiver is always enabled.)
371.TP
372.B CSIZE
373Number of bits per byte.
374.B CSIZE
375masks off the values
376.BR CS5 ,
377.BR CS6 ,
378.BR CS7
379and
380.BR CS8
381that indicate that 5, 6, 7 or 8 bits are used.
382.TP
383.B CSTOPB
384Send two stop bits instead of one. Two stop bits are normally used at 110
385baud or less.
386.TP
387.B PARENB
388Enable parity generation.
389.TP
390.B PARODD
391Generate odd parity if parity is generated, otherwise even parity.
392.TP
393.B HUPCL
394Drop the modem control lines on the last close of the terminal line. (Not
395implemented.)
396.SS "Local Modes"
397The
398.B c_lflag
399field contains the following single bit flags that control various functions:
400.TP
401.B ECHO
402Enable echoing of input characters. Most input characters are echoed as
403they are. Control characters are echoed as
404.BI "^" X
405where
406.I X
407is the letter used to say that the control character is
408.BI CTRL\- X\fR.
409The
410.BR CR ,
411.BR NL
412and
413.BR TAB
414characters are echoed with their normal effect unless they are escaped by
415.BR LNEXT .
416.TP
417.B ECHOE
418If
419.B ICANON
420and
421.B ECHO
422are set then echo
423.B ERASE
424and
425.B KILL
426as one or more backspace-space-backspace sequences to wipe out the last
427character or the entire line, otherwise they are echoed as they are.
428.TP
429.B ECHOK
430If
431.B ICANON
432and
433.B ECHO
434are set and
435.B ECHOE
436is not set then output an
437.B NL
438after the
439.B KILL
440character. (For hardcopy terminals it is best to unset
441.B ECHOE
442and to set
443.BR ECHOK .)
444.TP
445.B ECHONL
446Echo
447.B NL
448even if
449.B ECHO
450is not set, but
451.B ICANON
452is set.
453.TP
454.B ICANON
455Canonical input. This enables line oriented input and erase and kill
456processing.
457.TP
458.B IEXTEN
459Enable implementation defined input extensions.
460.TP
461.B ISIG
462Enable the signal characters
463.BR INTR ,
464.BR QUIT
465and
466.BR SUSP .
467.TP
468.B NOFLSH
469Disable the flushing of the input and output queues that is normally done if
470a signal is sent.
471.TP
472.B TOSTOP
473Send a
474.B SIGTTOU
475signal if job control is implemented and a background process tries to
476write. (MINIX 3 has no job control.)
477.SS "Input and output speed"
478The input and output speed are encoded into the
479.B c_ispeed
480and
481.B c_ospeed
482fields.
483.B <termios.h>
484defines the symbols
485.BR B0 ,
486.BR B50 ,
487.BR B75 ,
488.BR B110 ,
489.BR B134 ,
490.BR B150 ,
491.BR B200 ,
492.BR B300 ,
493.BR B600 ,
494.BR B1200 ,
495.BR B1800 ,
496.BR B2400 ,
497.BR B4800 ,
498.BR B9600 ,
499.BR B19200 ,
500.BR B38400 ,
501.BR B57600
502and
503.BR B115200
504as values used to indicate the given baud rates. The zero baud rate,
505.BR B0 ,
506if used for the input speed causes the input speed to be equal to the
507output speed. Setting the output speed to zero hangs up the line. One
508should use the functions
509.BR cfgetispeed() ,
510.BR cfgetospeed() ,
511.BR cfsetispeed()
512and
513.BR cfsetospeed()
514to get or set a speed, because the
515.B c_ispeed
516and
517.B c_ospeed
518fields may not be visible under other implementations. (The
519.B c_ispeed
520and
521.B c_ospeed
522fields and the
523.B B57600
524and
525.B B115200
526symbols are MINIX 3 specific.)
527.SS "Special characters"
528The
529.B c_cc
530array contains the special characters that can be modified. The array has
531length
532.B NCCS
533and is subscripted by the symbols
534.BR VEOF ,
535.BR VEOL ,
536.BR VERASE ,
537.BR VINTR ,
538.BR VKILL ,
539.BR VMIN ,
540.BR VQUIT ,
541.BR VTIME ,
542.BR VSUSP ,
543.BR VSTART ,
544.BR VSTOP ,
545.BR VREPRINT ,
546.BR VLNEXT
547and
548.BR VDISCARD .
549All these symbols are defined in
550.BR <termios.h> .
551Some implementations may give the same values to the
552.B VMIN
553and
554.B VTIME
555subscripts and the
556.B VEOF
557and
558.B VEOL
559subscripts respectively, and may ignore changes to
560.B START
561and
562.BR STOP .
563(Under MINIX 3 all special characters have their own
564.I c_cc
565slot and can all be modified.)
566.SS "Raw I/O Parameters"
567The
568.B MIN
569and
570.B TIME
571parameters can be used to adjust a raw connection to bursty input.
572.B MIN
573represents a minimum number of bytes that must be received before a read
574call returns.
575.B TIME
576is a timer of 0.1 second granularity that can be used to time out a read.
577Setting either of these parameters to zero has special meaning, which leads
578to the following four possibilities:
579.TP 5
580.B "MIN > 0, TIME > 0"
581.B TIME
582is an inter-byte timer that is started (and restarted) when a byte is
583received. A read succeeds when either the minimum number of characters
584is received or the timer expires. Note that the timer starts
585.B after
586the first character, so the read returns at least one byte.
587.TP
588.B "MIN > 0, TIME = 0"
589Now the timer is disabled, and a reader blocks indefinitely until at least
590.B MIN
591characters are received.
592.TP
593.B "MIN = 0, TIME > 0"
594.B TIME
595is now a read timer that is started when a read is executed. The read will
596return if the read timer expires or if at least one byte is input. (Note
597that a value of zero may be returned to the reader.)
598.TP
599.B "MIN = 0, TIME = 0"
600The bytes currently available are returned. Zero is returned if no bytes
601are available.
602.SS "User Level Functions"
603Termios attributes are set or examined, and special functions can be
604performed by using the functions described in
605.BR termios (3).
606.SS "Session Leaders and Process Groups"
607With the use of the
608.B setsid()
609function can a process become a session leader. A session leader forms a
610process group with a process group id equal to the process id of the session
611leader. If a session leader opens a terminal device file then this terminal
612becomes the controlling tty of the session leader. Unless the terminal is
613already the controlling tty of another process, or unless the
614.B O_NOCTTY
615flag is used to prevent the allocation of a controlling tty. The process
616group of the session leader is now remembered as the terminal process group
617for signals sent by the terminal driver. All the children and grandchildren
618of the session leader inherit the controlling terminal and process group
619until they themselves use
620.BR setsid() .
621.PP
622The controlling tty becomes inaccessible to the children of the session
623leader when the session leader exits, and a hangup signal is sent to all
624the members of the process group. The input and output queues are flushed
625on the last close of a terminal and all attributes are reset to the default
626state.
627.PP
628A special device
629.B /dev/tty
630is a synonym for the controlling tty of a process. It allows a process to
631reach the terminal even when standard input, output and error are
632redirected. Opening this device can also be used as a test to see if a
633process has a controlling tty or not.
634.PP
635For MINIX 3 a special write-only device
636.B /dev/log
637exists for processes that want to write messages to the system console.
638Unlike the console this device is still accessible when a session leader
639exits.
640.PP
641Minix-vmd also has a
642.B /dev/log
643device, but this device is read-write. All messages written to the log
644device or to the console when X11 is active can be read from
645.BR /dev/log .
646The system tries to preserve the log buffer over a reboot so that panic
647messages reappear in the log if the system happens to crash.
648.SS "Pseudo Terminals"
649Pseudo ttys allow a process such as a remote login daemon to set up a
650terminal for a remote login session. The login session uses a device like
651.B /dev/ttyp0
652for input and output, and the remote login daemon uses the device
653.B /dev/ptyp0
654to supply input to or take output from the login session and transfer this
655to or from the originating system. So the character flow may be: Local
656user input sent to the remote system is written to
657.B /dev/ptyp0
658by the remote login daemon, undergoes input processing and appears on
659.B /dev/ttyp0
660as input to the login session. Output from the login session to
661.B /dev/ttyp0
662undergoes output processing, is read from
663.B /dev/ptyp0
664by the remote login daemon and is send over to the local system to be
665displayed for the user. (So there are only four data streams to worry about
666in a pseudo terminal.)
667.PP
668A pseudo terminal can be allocated by trying to open all the controlling
669devices
670.BI /dev/pty nn
671one by one until it succeeds. Further opens will fail once a pty is open.
672The process should now fork, the child should become session leader, open
673the tty side of the pty and start a login session.
674.PP
675If the tty side is eventually closed down then reads from the pty side will
676return zero and writes return \-1 with
677.B errno
678set to
679.BR EIO .
680If the pty side is closed first then a
681.B SIGHUP
682signal is sent to the session leader and further reads from the tty side
683return zero and writes return \-1 with
684.B errno
685set to
686.BR EIO .
687(Special note: A line erase may cause up to three times the size of the
688tty input queue to be sent to the pty reader as backspace overstrikes. Some
689of this output may get lost if the pty reader cannot accept it all at once
690in a single read call.)
691.SS "Backwards compatibility"
692The
693.BR TIOCGETP ,
694.BR TIOCSETP ,
695.BR TIOCGETC
696and
697.BR TIOCSETC
698ioctl functions that are used by the old
699.B sgtty
700terminal interface are still supported by the terminal driver by emulation.
701Note that these old functions cannot control all termios attributes, so the
702terminal must be in a relatively sane state to avoid problems.
703.SH FILES
704The list below shows all devices that MINIX 3 and Minix-vmd have. Not all of
705these devices are configured in by default, as indicated by the numbers
706(i/j/k, l/m/n) that tell the minimum, default and maximum possible number of
707these devices for MINIX 3 (i/j/k) and Minix-vmd (l/m/n).
708.TP 20
709.B /dev/console
710System console.
711.TP
712.B /dev/ttyc[1-7]
713Virtual consoles. (0/1/7, 0/1/7)
714.TP
715.BR /dev/log
716Console log device.
717.TP
718.B /dev/tty0[0-3]
719Serial lines. (0/2/2, 4/4/4)
720.TP
721.B /dev/tty[p-w][0-f]
722Pseudo ttys. (0/0/64, 1/32/128)
723.TP
724.B /dev/pty[p-w][0-f]
725Associated pseudo tty controllers.
726.SH "SEE ALSO"
727.BR stty (1),
728.BR termios (3),
729.BR setsid (2),
730.BR read (2),
731.BR write (2).
732.SH BUGS
733A fair number of flags are not implemented under MINIX 3 (yet). Luckily they
734are very limited utility and only apply to RS-232, not to the user interface.
735.SH AUTHOR
736Kees J. Bot (kjb@cs.vu.nl)
Note: See TracBrowser for help on using the repository browser.