📄 tty.4
字号:
.TH TTY 4 .SH NAMEtty \- general terminal interface.SH DESCRIPTIONThis section describesboth a particular special file,and the general nature of the terminal interface..PPThe file.I /dev/ttyis, in each process, a synonymfor the control terminal associated with that process.It is useful for programs that wish tobe sure of writing messages on the terminalno matter how output has been redirected.It can also be used for programs that demand a file namefor output, when typed output is desiredand it is tiresome to find out which terminalis currently in use..PPAs for terminals in general: all of the low-speed asynchronouscommunications ports use thesame general interface, no matter whathardware is involved.The remainder of this section discussesthe common features of the interface..PPWhen a terminal file is opened, it causesthe process to wait until a connection is established.In practice user's programs seldom open thesefiles; they are opened by.I initand become a user'sinput and output file.The very first terminal file open in a process becomesthe.I "control terminal"for that process.The control terminal plays a specialrole in handling quit or interrupt signals, as discussedbelow.The control terminal is inherited by a child process during a.IR fork ,even if the control terminal is closed.The set of processes that thus share a control terminalis called a.I process.IR group ;all members of a process group receive certain signalstogether, see DEL below and.IR kill (2)..PPA terminal associated with one of these files ordinarilyoperates in full-duplex mode.Characters may be typed at any time,even while output is occurring, and are only lost when thesystem's character input buffers become completelychoked, which is rare,or when the user has accumulated the maximum allowed number ofinput characters that have not yet been read by some program.Currently this limit is 256 characters.When the input limit is reached all thesaved characters are thrown away without notice..PPNormally, terminal input is processed in units of lines.This means that a program attemptingto read will be suspended until an entire line has beentyped.Also, no matter how many characters are requestedin the read call, at most one line will be returned.It is not however necessary to read a whole line atonce; any number of characters may berequested in a read, even one, without losing information.There are special modes, discussed below,that permit the program to read each character as typedwithout waiting for a full line..PPDuring input, erase and kill processing is normallydone.By default, the character `#' erases thelast character typed, except that it will not erasebeyond the beginning of a line or an EOT.By default, the character `@' kills the entireline up to the point where it was typed, but not beyond an EOT.Both thesecharacters operate on a keystroke basis independentlyof any backspacing or tabbing that may have been done.Either `@' or `#' may be entered literally by precedingit by `\\';the erase or kill character remains, but the`\\' disappears.These two characters may be changed to others..PPWhen desired,all upper-case letters are mapped intothe corresponding lower-case letter.The upper-case letter may be generated by precedingit by `\\'.In addition, the following escape sequences can be generatedon output and accepted on input:.PP.nffor use\` \e\'| \\!~ \e^{ \e(} \e).fi.PPCertain ASCII control characters have special meaning.These characters are not passed to a reading programexcept in raw mode where they lose their special character.Also, it is possible to change these characters from the default;see below..TPEOT(Control-D) may be used to generate an end of filefrom a terminal.When an EOT is received, all the characterswaiting to be read are immediately passed tothe program, without waiting for a new-line,and the EOT is discarded.Thus if there are no characters waiting, whichis to say the EOT occurred at the beginning of a line,zero characters will be passed back, and this isthe standard end-of-file indication..TPDEL(Rubout)is not passed to a program but generatesan.I interruptsignalwhich is sent to all processes with the associated control terminal.Normally each such process is forced to terminate,but arrangements may be made either toignore the signal or to receive atrap to an agreed-upon location.See.IR signal (2)..TPFS(Control-\\ or control-shift-L)generates the.I quitsignal.Its treatment is identical to the interrupt signalexcept that unless a receiving process hasmade other arrangements it will not only be terminatedbut a core image file will be generated..TPDC3(Control-S) delays all printing on the terminaluntil something is typed in..TPDC1(Control-Q) restarts printing after DC3 without generatingany input to a program..PPWhen the carrier signal from the dataset drops (usuallybecause the user has hung up his terminal)a.I hangupsignal is sent to all processes with the terminalas control terminal.Unless other arrangements have been made,this signal causes the processes to terminate.If the hangup signal is ignored, any readreturns with an end-of-file indication.Thus programs that read a terminal and test forend-of-file on their inputcan terminate appropriately whenhung up on..PPWhen one or morecharacters are written, they are actually transmittedto the terminal as soon as previously-written charactershave finished typing.Input characters are echoed by putting them in the output queueas they arrive.When a process produces characters more rapidly than they can be typed,it will be suspended when its output queue exceeds some limit.When the queue has drained down to some thresholdthe program is resumed.Even parity is always generated on output.The EOT character is not transmitted(except in raw mode)to prevent terminalsthat respond to it from hanging up..PPSeveral.IR ioctl (2)calls apply to terminals.Most of them use the following structure,defined in.IR <sgtty.h> :.PP.nf.ft 3struct sgttyb { char sg_ispeed; char sg_ospeed; char sg_erase; char sg_kill; int sg_flags;};.ft R.fi.PPThe.I sg_ispeed and .I sg_ospeedfields describe the input and output speeds of thedevice according to the following table,which corresponds to the DEC DH-11 interface.If other hardware is used,impossible speed changes are ignored.Symbolic values in the table are as defined in.IR <sgtty.h> ..PP.nf.ta \w'B9600 'u +5nB0 0 (hang up dataphone)B50 1 50 baudB75 2 75 baudB110 3 110 baudB134 4 134.5 baudB150 5 150 baudB200 6 200 baudB300 7 300 baudB600 8 600 baudB1200 9 1200 baudB1800 10 1800 baudB2400 11 2400 baudB4800 12 4800 baudB9600 13 9600 baudEXTA 14 External AEXTB 15 External B.fi.DT.PPIn the current configuration,only 110, 150, 300 and 1200 baud are really supported on dial-up lines.Code conversion and line control required forIBM 2741's (134.5 baud)must be implemented by the user'sprogram.The half-duplex line disciplinerequired for the 202 dataset (1200 baud)is not supplied; full-duplex 212 datasets work fine..PPThe.I sg_eraseand.I sg_killfields of the argument structurespecify the erase and kill characters respectively.(Defaults are # and @.).PPThe.I sg_flagsfield of the argument structurecontains several bits that determine thesystem's treatment of the terminal:.PP.ta \w'ALLDELAY 'u +\w'0100000 'u.nfALLDELAY 0177400 Delay algorithm selectionBSDELAY 0100000 Select backspace delays (not implemented):BS0 0BS1 0100000VTDELAY 0040000 Select form-feed and vertical-tab delays:FF0 0FF1 0100000CRDELAY 0030000 Select carriage-return delays:CR0 0CR1 0010000CR2 0020000CR3 0030000TBDELAY 0006000 Select tab delays:TAB0 0TAB1 0001000TAB2 0004000XTABS 0006000NLDELAY 0001400 Select new-line delays:NL0 0NL1 0000400NL2 0001000NL3 0001400EVENP 0000200 Even parity allowed on input (most terminals)ODDP 0000100 Odd parity allowed on inputRAW 0000040 Raw mode: wake up on all characters, 8-bit interfaceCRMOD 0000020 Map CR into LF; echo LF or CR as CR-LFECHO 0000010 Echo (full duplex)LCASE 0000004 Map upper case to lower on inputCBREAK 0000002 Return each character as soon as typedTANDEM 0000001 Automatic flow control.DT.fi.PPThe delay bits specify how longtransmission stops to allow for mechanical or other movementwhen certain characters are sent to the terminal.In all cases a value of 0 indicates no delay..PPBackspace delays are currently ignored but mightbe used for Terminet 300's..PPIf a form-feed/vertical tab delay is specified,it lasts for about 2 seconds..PPCarriage-return delay type 1 lasts about .08 secondsand is suitable for the Terminet 300.Delay type 2 lasts about .16 seconds and is suitablefor the VT05 and the TI 700.Delay type 3 is unimplemented and is 0..PPNew-line delay type 1 is dependent on the current columnand is tuned for Teletype model 37's.Type 2 is useful for the VT05 and is about .10 seconds.Type 3 is unimplemented and is 0..PPTab delay type 1 is dependent on the amount of movementand is tuned to the Teletype model37.Type 3, called XTABS,is not a delay at all but causes tabs to be replacedby the appropriate number of spaces on output..PPCharacters with the wrong parity, as determined by bits 200 and100, are ignored..PPIn raw mode, every character is passed immediatelyto the program without waiting until a full line has been typed.No erase or kill processing is done;the end-of-file indicator (EOT), the interrupt character(DEL) and the quit character (FS) are not treated specially.There are no delays and no echoing, and no replacement ofone character for another;characters are a full 8 bits for both input and output(parity is up to the program)..PPMode 020 causes input carriage returns to be turned intonew-lines;input of either CR or LF causes LF-CR both tobe echoed(for terminals with a new-line function)..PPCBREAK is a sort of half-cooked (rare?) mode.Programs can read each character as soon as typed, insteadof waiting for a full line,but quit and interrupt work, and output delays, case-translation,CRMOD, XTABS, ECHO, and parity work normally.On the other hand there is no erase or kill,and no special treatment of \e or EOT..PPTANDEM mode causes the system to producea stop character (default DC3) whenever the inputqueue is in danger of overflowing, and a start character(default DC1)when the input queue has drained sufficiently.It is useful for flow control when the `terminal'is actually another machine that obeys the conventions..PPSeveral.I ioctlcalls have the form:.PP.B #include <sgtty.h>.PP.B ioctl(fildes, code, arg).br.B struct sgttyb *arg;.PPThe applicable codes are:.TPTIOCGETPFetch the parameters associated with the terminal, and storein the pointed-to structure..TPTIOCSETPSet the parameters according to the pointed-to structure.The interface delays until output is quiescent,then throws away any unread characters,before changing the modes..TPTIOCSETNSet the parameters but do not delay or flush input.Switching out of RAW or CBREAK modemay cause some garbage input..PPWith the following codes the.I argis ignored..TPTIOCEXCLSet ``exclusive-use'' mode:no further opens are permitted until the file has been closed..TPTIOCNXCLTurn off ``exclusive-use'' mode..TPTIOCHPCLWhen the file is closed for the last time,hang up the terminal.This is useful when the line is associatedwith an ACU used to place outgoing calls..TPTIOCFLUSHAll characters waiting in input or output queues are flushed..PPThe following codes affect characters that are specialto the terminal interface.The argument is a pointer to the following structure,defined in.IR <sgtty.h> :.PP.nf.ft 3struct tchars { char t_intrc; /* interrupt */ char t_quitc; /* quit */ char t_startc; /* start output */ char t_stopc; /* stop output */ char t_eofc; /* end-of-file */ char t_brkc; /* input delimiter (like nl) */};.fi.ft R.PPThe default values for these characters areDEL, FS, DC1, DC3, EOT, and \-1.A character value of \-1eliminates the effect of that character.The.I t_brkccharacter, by default \-1,acts like a new-line in that it terminates a `line,'is echoed, and is passed to the program.The `stop' and `start' characters may be the same,to produce a toggle effect.It is probably counterproductive to makeother special characters (including erase an kill)identical..PPThe calls are:.TPTIOCSETCChange the various special characters to those given in the structure..TPTIOCSETPSet the special characters to those given in the structure..SH FILES/dev/tty.br/dev/tty*.br/dev/console.SH SEE ALSOgetty(8), stty (1), signal(2), ioctl(2).SH BUGSHalf-duplex terminals are not supported..PPThe terminal handler has clearly entered therace for ever-greater complexity and generality.It's still not complex and general enough forTENEX fans.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -