subnets, netmask
[unix-history] / usr / src / share / man / man4 / tty.4
CommitLineData
b06ffe83 1.\" Copyright (c) 1983 Regents of the University of California.
02d430a1
KM
2.\" All rights reserved. The Berkeley software License Agreement
3.\" specifies the terms and conditions for redistribution.
4.\"
8ddf9ad9 5.\" @(#)tty.4 6.5 (Berkeley) %G%
02d430a1 6.\"
b06ffe83 7.TH TTY 4 ""
02d430a1
KM
8.UC 4
9.SH NAME
10tty \- general terminal interface
9313e78d
KM
11.SH SYNOPSIS
12.B #include <sgtty.h>
02d430a1
KM
13.SH DESCRIPTION
14This section describes
15both a particular special file
16.B /dev/tty
17and the terminal drivers used for conversational computing.
18.LP
19.B Line disciplines.
20.PP
21The system provides different
22.I "line disciplines"
23for controlling communications lines.
24In this version of the system there are three disciplines available:
25.IP "old" 8
26The old (standard) terminal driver. This is used when using the
27standard shell
28.IR sh (1)
29and for compatibility with other standard version 7 UNIX systems.
30.IP "new"
31A newer terminal driver, with features for job control; this must
32be used when using
33.IR csh (1).
02d430a1
KM
34.IP "net"
35A line discipline used for networking and loading data into
36the system over communications lines. It allows high speed input
37at very low overhead, and is described in
38.IR bk (4).
39.LP
40Line discipline switching is accomplished with the TIOCSETD
3e0098f5 41.IR ioctl :
02d430a1 42.IP
3e0098f5
KM
43.B "int ldisc = LDISC;"
44.br
45.B "ioctl(f, TIOCSETD, &ldisc);"
02d430a1
KM
46.LP
47where LDISC is OTTYDISC for the standard tty driver, NTTYDISC for the new
48driver and NETLDISC for the networking discipline.
49The standard (currently old) tty driver is discipline 0 by convention.
3e0098f5
KM
50The current line discipline can be obtained with the TIOCGETD
51.IR ioctl .
02d430a1
KM
52Pending input is discarded when the line discipline is changed.
53.PP
54All of the low-speed asynchronous
55communications ports can use any
56of the available line disciplines, no matter what
57hardware is involved.
58The remainder of this section discusses the
59\*(lqold\*(rq and \*(lqnew\*(rq disciplines.
60.LP
61.B "The control terminal."
62.LP
63When a terminal file is opened, it causes the process to wait until a
64connection is established. In practice, user programs seldom open
65these files; they are opened by
66.IR init (8)
67and become a user's standard input and output file.
68.PP
69If a process which has no control terminal opens a terminal file, then
70that terminal file becomes the control terminal for that process.
71The control terminal is thereafter inherited by a child process during a
72.IR fork (2),
73even if the control terminal is closed.
74.LP
75The file
76.B /dev/tty
77is, in each process, a synonym for a
78.I "control terminal"
79associated with that process. It is useful for programs that wish to
80be sure of writing messages on the terminal
81no matter how output has been redirected.
82It can also be used for programs that demand a file name
83for output, when typed output is desired
84and it is tiresome to find out which terminal
85is currently in use.
86.LP
3e0098f5
KM
87A process can remove the association it has with its controlling
88terminal by opening the file
89.B /dev/tty
90and issuing a
91.IP
92.B "ioctl(f, TIOCNOTTY, 0);"
93.LP
94This is often desirable in server processes.
95.LP
02d430a1
KM
96.B "Process groups."
97.LP
9313e78d 98Command processors such as
02d430a1
KM
99.IR csh (1)
100can arbitrate the terminal between different
101.I jobs
102by placing related jobs in a single process group and associating this
3e0098f5 103process group with the terminal. A terminal's associated process group
02d430a1
KM
104may be set using the TIOCSPGRP
105.IR ioctl (2):
106.IP
3e0098f5 107.B "ioctl(fildes, TIOCSPGRP, &pgrp);"
02d430a1 108.LP
3e0098f5 109or examined using TIOCGPGRP, which returns the current
02d430a1 110process group in
3e0098f5 111.IR pgrp .
02d430a1
KM
112The new terminal driver aids in this arbitration by restricting access
113to the terminal by processes which are not in the current process group;
114see
115.B "Job access control"
116below.
117.LP
118.B "Modes."
119.PP
120The terminal drivers have three major modes, characterized by the
121amount of processing on the input and output characters:
122.IP cooked 10
123The normal mode. In this mode lines of input are collected and input editing
124is done. The edited line is made available when it is completed by
125a newline
3e0098f5 126or when the \fIt_brkc\fP character, normally an EOT (control-D, hereafter ^D),
02d430a1
KM
127is entered.
128A carriage return is usually made synonymous with newline in this mode,
129and replaced with a newline whenever it is typed.
130All driver functions
131(input editing, interrupt generation,
132output processing such as delay generation and tab expansion, etc.)
133are available in this mode.
134.IP CBREAK 10
135This mode eliminates the character, word, and line editing input facilities,
136making the input character available to the user program as it is typed.
137Flow control, literal-next and interrupt processing are still done in this mode.
138Output processing is done.
139.IP RAW 10
140This mode eliminates all input processing and makes all input characters
141available as they are typed; no output processing is done either.
142.PP
9313e78d
KM
143The style of input processing can also be very different when
144the terminal is put in non-blocking i/o mode; see
3e0098f5 145the FNDELAY flag as described in
9313e78d
KM
146.IR fcntl (2).
147In this case a
02d430a1
KM
148.IR read (2)
149from the control terminal will never block, but rather
9313e78d
KM
150return an error indication (EWOULDBLOCK) if there is no
151input available.
152.PP
153A process may also request a SIGIO signal be sent it whenever input
154is present. To enable this mode the FASYNC flag should be set using
155.IR fcntl (2).
02d430a1
KM
156.LP
157.B "Input editing."
158.LP
159A UNIX terminal ordinarily operates in full-duplex mode.
160Characters may be typed at any time,
161even while output is occurring, and are only lost when the
162system's character input buffers become completely
163choked, which is rare,
164or when the user has accumulated the maximum allowed number of
165input characters that have not yet been read by some program.
166Currently this limit is 256 characters.
3e0098f5
KM
167In RAW mode, the terminal driver
168throws away all input and output without notice when the limit is reached.
169In CBREAK or cooked mode it refuses to accept any further input and,
170if in the new line discipline, rings the terminal bell.
02d430a1
KM
171.PP
172Input characters are normally accepted in either even or odd parity
173with the parity bit being stripped off before the character is given to
174the program. By clearing either the EVEN or ODD bit in the flags word
175it is possible to have input characters with that parity discarded (see the
176\fBSummary\fR below.)
177.PP
178In all of the line disciplines, it is possible to simulate terminal
3e0098f5
KM
179input using the TIOCSTI
180.IR ioctl ,
181which takes, as its third argument,
02d430a1
KM
182the address of a character. The system pretends that this character
183was typed on the argument terminal, which must be the control terminal except
9313e78d 184for the super-user (this call is not in standard version 7 UNIX).
02d430a1
KM
185.PP
186Input characters are normally echoed by putting them in an output queue
187as they arrive. This may be disabled by clearing the ECHO bit in the
188flags word using the
3e0098f5
KM
189.IR stty (3C)
190call or the TIOCSETN or TIOCSETP
191.IR ioctl s
02d430a1
KM
192(see the \fBSummary\fR below).
193.PP
194In cooked mode, terminal input is processed in units of lines.
195A program attempting
196to read will normally be suspended until an entire line has been
197received
70fd5b48
JL
198(but see the description of SIGTTIN in \fBJob access control\fR
199and of FIONREAD in
200\fBSummary\fR, both below.)
02d430a1
KM
201No matter how many characters are requested
202in the read call, at most one line will be returned.
203It is not, however, necessary to read a whole line at
204once; any number of characters may be
205requested in a read, even one, without losing information.
206.PP
3e0098f5
KM
207During input, line editing is normally done, with the DELETE character
208logically erasing the last character typed and the character ^U (control-U)
02d430a1 209logically erasing the entire current input line.
02d430a1
KM
210These characters
211never erase beyond the beginning of the current input line or an ^D.
212These characters may be entered literally by
3e0098f5
KM
213preceding them with `\e\|'; the `\e\|' will normally be erased when the
214character is typed.
02d430a1
KM
215.PP
216The drivers normally treat either a carriage return or a newline character
217as terminating an input line, replacing the return with a newline and echoing
218a return and a line feed.
219If the CRMOD bit is cleared in the local mode word then the processing
220for carriage return is disabled, and it is simply echoed as a return,
221and does not terminate cooked mode input.
222.PP
223In the new driver there is a literal-next character ^V which can be typed
224in both cooked and CBREAK mode preceding
3e0098f5 225.I any
02d430a1 226character to prevent its special meaning. This is to be preferred to the
3e0098f5
KM
227use of `\e\|' escaping erase and kill characters, but `\e\|' is
228retained with its old function in the new line discipline.
02d430a1
KM
229.PP
230The new terminal driver also provides two other editing characters in
231normal mode. The word-erase character, normally ^W, erases the preceding
232word, but not any spaces before it. For the purposes of ^W, a word
233is defined as a sequence of non-blank characters, with tabs counted as
234blanks.
235Finally, the reprint character, normally ^R, retypes the pending input beginning
9313e78d 236on a new line. Retyping occurs automatically in cooked mode if characters
02d430a1
KM
237which would normally be erased from the screen are fouled by program output.
238.LP
239.B "Input echoing and redisplay"
240.LP
3e0098f5
KM
241The terminal driver has several modes (not present in standard UNIX
242Version 7 systems) for handling the echoing of
02d430a1
KM
243terminal input, controlled by bits in a local mode word.
244.LP
245.I "Hardcopy terminals."
246When a hardcopy terminal is in use, the LPRTERA bit is normally set in
247the local mode word. Characters which are logically erased are
248then printed out backwards preceded by `\e\|' and followed by `/' in this mode.
249.LP
3e0098f5
KM
250.I "CRT terminals."
251When a CRT terminal is in use, the LCRTBS bit is normally set in the local
02d430a1
KM
252mode word. The terminal driver then echoes the proper number of erase
253characters when input is erased; in the normal case where the erase
254character is a ^H this causes the cursor of the terminal to back up
255to where it was before the logically erased character was typed.
256If the input has become fouled due to interspersed asynchronous output,
9313e78d 257the input is automatically retyped.
02d430a1 258.LP
3e0098f5
KM
259.I "Erasing characters from a CRT."
260When a CRT terminal is in use, the LCRTERA bit may be set to cause
02d430a1
KM
261input to be erased from the screen with a \*(lqbackspace-space-backspace\*(rq
262sequence when character or word deleting sequences are used.
263A LCRTKIL bit may be set as well, causing the input to
264be erased in this manner on line kill sequences as well.
265.LP
266.I "Echoing of control characters."
267If the LCTLECH bit is set in the local state word, then non-printing (control)
268characters are normally echoed as ^X (for some X)
269rather than being echoed unmodified; delete is echoed as ^?.
270.LP
3e0098f5 271The normal modes for use on CRT terminals are speed dependent.
02d430a1
KM
272At speeds less than 1200 baud, the LCRTERA and LCRTKILL processing
273is painfully slow, so
274.IR stty (1)
275normally just sets LCRTBS and LCTLECH; at
276speeds of 1200 baud or greater all of these bits are normally set.
277.IR Stty (1)
278summarizes these option settings and the use of the new terminal
279driver as
280\*(lqnewcrt.\*(rq
281.LP
282.B "Output processing."
283.PP
284When one or more
285characters are written, they are actually transmitted
286to the terminal as soon as previously-written characters
287have finished typing.
288(As noted above, input characters are normally
289echoed by putting them in the output queue
290as they arrive.)
291When a process produces characters more rapidly than they can be typed,
292it will be suspended when its output queue exceeds some limit.
293When the queue has drained down to some threshold
294the program is resumed.
295Even parity is normally generated on output.
296The EOT character is not transmitted in cooked mode to prevent terminals
3e0098f5 297that respond to it from hanging up; programs using RAW or CBREAK mode
02d430a1
KM
298should be careful.
299.PP
300The terminal drivers provide necessary processing for cooked and CBREAK mode
301output including delay generation for certain special characters and parity
302generation. Delays are available after backspaces ^H, form feeds ^L,
303carriage returns ^M, tabs ^I and newlines ^J. The driver will also optionally
304expand tabs into spaces, where the tab stops are assumed to be set every
3e0098f5
KM
305eight columns, and optionally convert newlines to carriage returns
306followed by newline. These functions are controlled by bits in the tty
307flags word; see \fBSummary\fR below.
02d430a1
KM
308.PP
309The terminal drivers provide for mapping between upper and lower case
310on terminals lacking lower case, and for other special processing on
311deficient terminals.
312.PP
313Finally, in the new terminal driver, there is a output flush character,
314normally ^O, which sets the LFLUSHO bit in the local mode word, causing
315subsequent output to be flushed until it is cleared by a program or more
316input is typed. This character has effect in both cooked and CBREAK modes
317and causes pending input to be retyped if there is any pending input.
3e0098f5
KM
318An
319.I ioctl
320to flush the characters in the input or output queues, TIOCFLUSH,
9313e78d 321is also available.
02d430a1
KM
322.LP
323.B "Upper case terminals and Hazeltines"
324.PP
325If the LCASE bit is set in the tty flags, then
326all upper-case letters are mapped into
327the corresponding lower-case letter.
328The upper-case letter may be generated by preceding
329it by `\\'.
3e0098f5 330Upper case letters are preceded by a `\e\|' when output.
02d430a1
KM
331In addition, the following escape sequences can be generated
332on output and accepted on input:
333.PP
334.nf
335for \` | ~ { }
336use \e\|\' \e\|! \e\|^ \e\|( \e\|)
337.fi
338.PP
339To deal with Hazeltine terminals, which do not understand that ~ has
340been made into an ASCII character, the LTILDE bit may be set in the local
3e0098f5 341mode word; in this case the character
02d430a1
KM
342~ will be replaced with the character \` on output.
343.LP
344.B "Flow control."
345.PP
346There are two characters (the stop character, normally ^S, and the
347start character, normally ^Q) which cause output to be suspended and
348resumed respectively. Extra stop characters typed when output
349is already stopped have no effect, unless the start and stop characters
350are made the same, in which case output resumes.
351.PP
352A bit in the flags word may be set to put the terminal into TANDEM mode.
353In this mode the system produces a stop character (default ^S) when
354the input queue is in danger of overflowing, and a start character (default
355^Q) when the input has drained sufficiently. This mode is useful
356when the terminal is actually another machine that obeys the
357conventions.
358.LP
359.B "Line control and breaks."
360.LP
361There are several
362.I ioctl
363calls available to control the state of the terminal line.
3e0098f5
KM
364The TIOCSBRK
365.I ioctl
366will set the break bit in the hardware interface
02d430a1
KM
367causing a break condition to exist; this can be cleared (usually after a delay
368with
369.IR sleep (3))
370by TIOCCBRK.
371Break conditions in the input are reflected as a null character in RAW mode
372or as the interrupt character in cooked or CBREAK mode.
3e0098f5
KM
373The TIOCCDTR
374.I ioctl
375will clear the data terminal ready condition; it can
02d430a1
KM
376be set again by TIOCSDTR.
377.PP
378When the carrier signal from the dataset drops (usually
379because the user has hung up his terminal) a
380SIGHUP hangup signal is sent to the processes in the distinguished
381process group of the terminal; this usually causes them to terminate
382(the SIGHUP can be suppressed by setting the LNOHANG bit in the local
383state word of the driver.)
384Access to the terminal by other processes is then normally revoked,
385so any further reads will fail, and programs that read a terminal and test for
386end-of-file on their input will terminate appropriately.
387.PP
388When using an ACU
389it is possible to ask that the phone line be hung up on the last close
3e0098f5
KM
390with the TIOCHPCL
391.IR ioctl ;
392this is normally done on the outgoing line.
02d430a1
KM
393.LP
394.B "Interrupt characters."
395.PP
396There are several characters that generate interrupts in cooked and CBREAK
3e0098f5
KM
397mode; all are sent to the processes in the control group of the terminal,
398as if a TIOCGPGRP
399.I ioctl
400were done to get the process group and then a
02d430a1
KM
401.IR killpg (2)
402system call were done,
403except that these characters also flush pending input and output when
404typed at a terminal
405(\fI\z'a\`'la\fR TIOCFLUSH).
406The characters shown here are the defaults; the field names in the structures
407(given below)
408are also shown.
3e0098f5
KM
409The characters may be changed.
410.IP ^C
411\fBt_intrc\fR (ETX) generates a SIGINT signal.
02d430a1
KM
412This is the normal way to stop a process which is no longer interesting,
413or to regain control in an interactive program.
414.IP ^\e
415\fBt_quitc\fR (FS) generates a SIGQUIT signal.
416This is used to cause a program to terminate and produce a core image,
417if possible,
418in the file
419.B core
420in the current directory.
421.IP ^Z
422\fBt_suspc\fR (EM) generates a SIGTSTP signal, which is used to suspend
423the current process group.
424.IP ^Y
9313e78d 425\fBt_dsuspc\fR (SUB) generates a SIGTSTP signal as ^Z does, but the
02d430a1
KM
426signal is sent when a program attempts to read the ^Y, rather than when
427it is typed.
428.LP
429.B "Job access control."
430.PP
431When using the new terminal driver,
432if a process which is not in the distinguished process group of its
433control terminal attempts to read from that terminal its process group is
9313e78d
KM
434sent a SIGTTIN signal. This signal normally causes the members of
435that process group to stop.
436If, however, the process is ignoring SIGTTIN, has SIGTTIN blocked,
9313e78d 437or is in the middle of process creation using
02d430a1 438.IR vfork (2)),
3e0098f5
KM
439the read will return \-1 and set
440.I errno
441to EIO.
02d430a1
KM
442.PP
443When using the new terminal driver with the LTOSTOP bit set in the local
444modes, a process is prohibited from writing on its control terminal if it is
445not in the distinguished process group for that terminal.
3e0098f5
KM
446Processes which are holding or ignoring SIGTTOU signals
447or which are in the middle of a
02d430a1
KM
448.IR vfork (2)
449are excepted and allowed to produce output.
450.LP
451.B "Summary of modes."
452.LP
453Unfortunately, due to the evolution of the terminal driver,
454there are 4 different structures which contain various portions of the
455driver data. The first of these (\fBsgttyb\fR)
456contains that part of the information
457largely common between version 6 and version 7 UNIX systems.
458The second contains additional control characters added in version 7.
3e0098f5 459The third is a word of local state added in 4BSD,
02d430a1
KM
460and the fourth is another structure of special characters added for the
461new driver. In the future a single structure may be made available
462to programs which need to access all this information; most programs
463need not concern themselves with all this state.
464.de Ul
465.ie t \\$1\l'|0\(ul'
466.el \fI\\$1\fP
467..
468.LP
469.Ul "Basic modes: sgtty."
470.PP
471The basic
472.IR ioctl s
473use the structure
474defined in
475.IR <sgtty.h> :
476.PP
477.ta .5i 1i
478.nf
479.ft 3
480struct sgttyb {
481 char sg_ispeed;
482 char sg_ospeed;
483 char sg_erase;
484 char sg_kill;
485 short sg_flags;
486};
487.ft R
488.fi
489.PP
490The
491.I sg_ispeed
492and
493.I sg_ospeed
494fields describe the input and output speeds of the
495device according to the following table,
496which corresponds to the DEC DH-11 interface.
497If other hardware is used,
498impossible speed changes are ignored.
499Symbolic values in the table are as defined in
500.IR <sgtty.h> .
501.PP
502.nf
503.ta \w'B9600 'u +5n
504B0 0 (hang up dataphone)
505B50 1 50 baud
506B75 2 75 baud
507B110 3 110 baud
508B134 4 134.5 baud
509B150 5 150 baud
510B200 6 200 baud
511B300 7 300 baud
512B600 8 600 baud
513B1200 9 1200 baud
514B1800 10 1800 baud
515B2400 11 2400 baud
516B4800 12 4800 baud
517B9600 13 9600 baud
518EXTA 14 External A
519EXTB 15 External B
520.fi
521.DT
522.PP
02d430a1
KM
523Code conversion and line control required for
524IBM 2741's (134.5 baud)
525must be implemented by the user's
526program.
527The half-duplex line discipline
528required for the 202 dataset (1200 baud)
529is not supplied; full-duplex 212 datasets work fine.
530.PP
531The
532.I sg_erase
533and
534.I sg_kill
535fields of the argument structure
536specify the erase and kill characters respectively.
3e0098f5 537(Defaults are DELETE and ^U.)
02d430a1
KM
538.PP
539The
540.I sg_flags
541field of the argument structure
542contains several bits that determine the
543system's treatment of the terminal:
544.PP
545.ta \w'ALLDELAY 'u +\w'0100000 'u
546.nf
547ALLDELAY 0177400 Delay algorithm selection
548BSDELAY 0100000 Select backspace delays (not implemented):
549BS0 0
550BS1 0100000
551VTDELAY 0040000 Select form-feed and vertical-tab delays:
552FF0 0
8ddf9ad9 553FF1 0040000
02d430a1
KM
554CRDELAY 0030000 Select carriage-return delays:
555CR0 0
556CR1 0010000
557CR2 0020000
558CR3 0030000
559TBDELAY 0006000 Select tab delays:
560TAB0 0
8ddf9ad9 561TAB1 0002000
02d430a1
KM
562TAB2 0004000
563XTABS 0006000
564NLDELAY 0001400 Select new-line delays:
565NL0 0
566NL1 0000400
567NL2 0001000
568NL3 0001400
3e0098f5
KM
569EVENP 0000200 Even parity allowed on input and generated on output
570ODDP 0000100 Odd parity allowed on input and generated on output
02d430a1 571RAW 0000040 Raw mode: wake up on all characters, 8-bit interface
3e0098f5 572CRMOD 0000020 Map CR into LF; output LF as CR-LF
02d430a1 573ECHO 0000010 Echo (full duplex)
3e0098f5 574LCASE 0000004 Map upper case to lower on input and lower to upper on output
02d430a1
KM
575CBREAK 0000002 Return each character as soon as typed
576TANDEM 0000001 Automatic flow control
577.DT
578.fi
579.PP
580The delay bits specify how long
581transmission stops to allow for mechanical or other movement
582when certain characters are sent to the terminal.
583In all cases a value of 0 indicates no delay.
584.PP
585Backspace delays are currently ignored but might
586be used for Terminet 300's.
587.PP
588If a form-feed/vertical tab delay is specified,
589it lasts for about 2 seconds.
590.PP
591Carriage-return delay type 1 lasts about .08 seconds
592and is suitable for the Terminet 300.
593Delay type 2 lasts about .16 seconds and is suitable
594for the VT05 and the TI 700.
595Delay type 3 is suitable for the concept-100 and pads lines
596to be at least 9 characters at 9600 baud.
597.PP
598New-line delay type 1 is dependent on the current column
599and is tuned for Teletype model 37's.
600Type 2 is useful for the VT05 and is about .10 seconds.
601Type 3 is unimplemented and is 0.
602.PP
603Tab delay type 1 is dependent on the amount of movement
604and is tuned to the Teletype model
60537.
606Type 3, called XTABS,
607is not a delay at all but causes tabs to be replaced
608by the appropriate number of spaces on output.
609.PP
610Input characters with the wrong parity, as determined by bits 200 and
611100, are ignored in cooked and CBREAK mode.
612.PP
613RAW
614disables all processing save output flushing with LFLUSHO;
615full 8 bits of input are given as soon as
616it is available; all 8 bits are passed on output.
617A break condition in the input is reported as a null character.
3e0098f5
KM
618If the input queue overflows in raw mode all data in the input and output
619queues are discarded; this applies to both new and old drivers.
02d430a1
KM
620.PP
621CRMOD causes input carriage returns to be turned into
3e0098f5
KM
622new-lines, and output and echoed new-lines to be output as a carriage return
623followed by a line feed.
02d430a1
KM
624.PP
625CBREAK is a sort of half-cooked (rare?) mode.
626Programs can read each character as soon as typed, instead
627of waiting for a full line;
628all processing is done except the input editing:
629character and word erase and line kill, input reprint,
3e0098f5 630and the special treatment of \e and EOT are disabled.
02d430a1
KM
631.PP
632TANDEM mode causes the system to produce
633a stop character (default ^S) whenever the input
634queue is in danger of overflowing, and a start character
635(default ^Q)
636when the input queue has drained sufficiently.
637It is useful for flow control when the `terminal'
638is really another computer which understands the conventions.
639.LP
3e0098f5
KM
640.B Note:
641The same ``stop'' and ``start'' characters are used for both directions
642of flow control; the
643.I t_stopc
644character is accepted on input as the character that stops output and is
645produced on output as the character to stop input, and the
646.I t_startc
647character is accepted on input as the character that restarts output and is
648produced on output as the character to restart input.
649.LP
02d430a1
KM
650.Ul "Basic ioctls"
651.PP
3e0098f5 652A large number of
02d430a1 653.IR ioctl (2)
3e0098f5 654calls apply to terminals. Some have the general form:
02d430a1
KM
655.PP
656.B #include <sgtty.h>
657.PP
658.B ioctl(fildes, code, arg)
659.br
660.B struct sgttyb *arg;
661.PP
662The applicable codes are:
663.IP TIOCGETP 15
664Fetch the basic parameters associated with the terminal, and store
665in the pointed-to \fIsgttyb\fR structure.
666.IP TIOCSETP
667Set the parameters according to the pointed-to \fIsgttyb\fR structure.
668The interface delays until output is quiescent,
669then throws away any unread characters,
670before changing the modes.
671.IP TIOCSETN
672Set the parameters like TIOCSETP but do not delay or flush input.
673Input is not preserved, however, when changing to or from RAW.
674.PP
3e0098f5 675With the following codes
02d430a1
KM
676.I arg
677is ignored.
678.IP TIOCEXCL 15
679Set \*(lqexclusive-use\*(rq mode:
680no further opens are permitted until the file has been closed.
681.IP TIOCNXCL
682Turn off \*(lqexclusive-use\*(rq mode.
683.IP TIOCHPCL
684When the file is closed for the last time,
685hang up the terminal.
686This is useful when the line is associated
687with an ACU used to place outgoing calls.
3e0098f5
KM
688.PP
689With the following codes
690.I arg
691is a pointer to an
692.BR int .
693.IP TIOCGETD 15
694.I arg
695is a pointer to an
696.B int
697into which is placed the current line discipline number.
698.IP TIOCSETD
699.I arg
700is a pointer to an
701.B int
702whose value becomes the current line discipline number.
02d430a1 703.IP TIOCFLUSH
3e0098f5
KM
704If the
705.B int
706pointed to by
707.I arg
708has a zero value, all characters waiting in input or output queues are flushed.
709Otherwise, the value of the
710.B int
711is treated as the logical OR of the FREAD and FWRITE defined in
712.BR <sys/file.h> ;
713if the FREAD bit is set, all characters waiting in input queues are flushed,
714and if the FWRITE bit is set, all characters waiting in output queues are
715flushed.
02d430a1
KM
716.LP
717The remaining calls are not available in vanilla version 7 UNIX.
718In cases where arguments are required, they are described; \fIarg\fR
719should otherwise be given as 0.
720.IP TIOCSTI 15
3e0098f5
KM
721the argument points to a character which the system
722pretends had been typed on the terminal.
02d430a1
KM
723.IP TIOCSBRK 15
724the break bit is set in the terminal.
725.IP TIOCCBRK
726the break bit is cleared.
727.IP TIOCSDTR
728data terminal ready is set.
729.IP TIOCCDTR
730data terminal ready is cleared.
3e0098f5
KM
731.IP TIOCSTOP 15
732output is stopped as if the ``stop'' character had been typed.
733.IP TIOCSTART
734output is restarted as if the ``start'' character had been typed.
02d430a1 735.IP TIOCGPGRP
3e0098f5
KM
736.I arg
737is a pointer to an
738.B int
739into which is placed the process group ID of the process group
740for which this terminal is the control terminal.
02d430a1 741.IP TIOCSPGRP
3e0098f5
KM
742.I arg
743is a pointer to an
744.B int
745(typically a process ID); the process group whose process group ID
746is the value of this
747.B int
748becomes the process group for which this terminal is the control terminal.
749.IP TIOCOUTQ
750returns in the
751.B int
752pointed to by
753.I arg
754the number of characters queued up to be output to the terminal.
02d430a1 755.IP FIONREAD
3e0098f5
KM
756returns in the
757.B int
758pointed to by
759.I arg
760the number of immediately readable characters from the argument unit.
761This works for files, pipes, and terminals.
762.PP
02d430a1
KM
763.Ul Tchars
764.PP
765The second structure associated with each terminal specifies
766characters that are special in both the old and new terminal interfaces:
767The following structure is defined in
768.IR <sys/ioctl.h> ,
769which is automatically included in
770.IR <sgtty.h> :
771.PP
772.nf
773.ft 3
774.ta .5i 1i 2i
775struct tchars {
776 char t_intrc; /* interrupt */
777 char t_quitc; /* quit */
778 char t_startc; /* start output */
779 char t_stopc; /* stop output */
780 char t_eofc; /* end-of-file */
781 char t_brkc; /* input delimiter (like nl) */
782};
783.DT
784.fi
785.ft R
786.PP
787The default values for these characters are
8ddf9ad9 788^C, ^\e\|, ^Q, ^S, ^D, and \-1.
02d430a1
KM
789A character value of \-1
790eliminates the effect of that character.
791The
792.I t_brkc
793character, by default \-1,
794acts like a new-line in that it terminates a `line,'
795is echoed, and is passed to the program.
796The `stop' and `start' characters may be the same,
797to produce a toggle effect.
798It is probably counterproductive to make
799other special characters (including erase and kill)
800identical.
3e0098f5
KM
801The applicable
802.I ioctl
803calls are:
02d430a1
KM
804.IP TIOCGETC 12
805Get the special characters and put them in the specified structure.
806.IP TIOCSETC 12
807Set the special characters to those given in the structure.
808.LP
809.Ul "Local mode"
810.PP
3e0098f5 811The third structure associated with each terminal is a local mode word.
02d430a1
KM
812The bits of the local mode word are:
813.sp
814.nf
815LCRTBS 000001 Backspace on erase rather than echoing erase
816LPRTERA 000002 Printing terminal erase mode
817LCRTERA 000004 Erase character echoes as backspace-space-backspace
818LTILDE 000010 Convert ~ to \` on output (for Hazeltine terminals)
819LMDMBUF 000020 Stop/start output when carrier drops
820LLITOUT 000040 Suppress output translations
821LTOSTOP 000100 Send SIGTTOU for background output
822LFLUSHO 000200 Output is being flushed
823LNOHANG 000400 Don't send hangup when carrier drops
824LETXACK 001000 Diablo style buffer hacking (unimplemented)
825LCRTKIL 002000 BS-space-BS erase entire line on line kill
b06ffe83 826LPASS8 004000 Pass all 8 bits through on input, in any mode
02d430a1
KM
827LCTLECH 010000 Echo input control chars as ^X, delete as ^?
828LPENDIN 020000 Retype pending input at next read or input character
829LDECCTQ 040000 Only ^Q restarts output after ^S, like DEC systems
3e0098f5 830LNOFLSH 100000 Inhibit flushing of pending I/O when an interrupt character is typed.
02d430a1
KM
831.fi
832.sp
833The applicable
834.I ioctl
835functions are:
836.IP TIOCLBIS 15
3e0098f5
KM
837.I arg
838is a pointer to an
839.B int
840whose value is a mask containing the bits to be set in the local mode word.
02d430a1 841.IP TIOCLBIC
3e0098f5
KM
842.I arg
843is a pointer to an
844.B int
845whose value is a mask containing the bits to be cleared in the local mode word.
02d430a1 846.IP TIOCLSET
3e0098f5
KM
847.I arg
848is a pointer to an
849.B int
850whose value is stored in the local mode word.
02d430a1 851.IP TIOCLGET
3e0098f5
KM
852.I arg
853is a pointer to an
854.B int
855into which the current local mode word is placed.
02d430a1
KM
856.LP
857.Ul "Local special chars"
858.PP
859The
860final structure associated with each terminal is the
861.I ltchars
3e0098f5 862structure which defines control characters
02d430a1
KM
863for the new terminal driver.
864Its structure is:
865.nf
866.sp
867.ta .5i 1i 2i
868.ft B
869struct ltchars {
870 char t_suspc; /* stop process signal */
9313e78d 871 char t_dsuspc; /* delayed stop process signal */
02d430a1
KM
872 char t_rprntc; /* reprint line */
873 char t_flushc; /* flush output (toggles) */
9313e78d 874 char t_werasc; /* word erase */
02d430a1
KM
875 char t_lnextc; /* literal next character */
876};
877.ft R
878.fi
879.sp
880The default values for these characters are ^Z, ^Y, ^R, ^O, ^W, and ^V.
881A value of \-1 disables the character.
882.PP
883The applicable \fIioctl\fR functions are:
884.IP TIOCSLTC 12
3e0098f5
KM
885.I arg
886is a pointer to an
02d430a1
KM
887.I ltchars
888structure which defines the new local special characters.
889.IP TIOCGLTC 12
3e0098f5
KM
890.I arg
891is a pointer to an
02d430a1
KM
892.I ltchars
893structure into which is placed the current set of local special characters.
894.SH FILES
895/dev/tty
896.br
897/dev/tty*
898.br
899/dev/console
900.SH SEE ALSO
9313e78d
KM
901csh(1),
902stty(1),
903ioctl(2),
904sigvec(2),
905stty(3C),
906getty(8),
907init(8)
02d430a1
KM
908.SH BUGS
909Half-duplex terminals are not supported.