tty.4

来自「<B>Digital的Unix操作系统VAX 4.2源码</B>」· 4 代码 · 共 1,190 行 · 第 1/3 页

4
1,190
字号
.\" SCCSID: @(#)tty.4	2.3	6/8/87.TH tty 4.SH Nametty \- general terminal interface.SH Description.PP.B "Terminal Subsystem".spThe terminal subsystem is the part of the operating systemthat allows users to read and write characters over asynchronous terminal lines.  An important aspect of thissubsystem is to provide a means for the user to set and receive terminalattributes.  Terminal attributes involve such things as linespeed (baud rate), character length, parity, flow control,modem control,as well as numerous character-processing capabilities..PPThe ULTRIX terminal interface allows the user to specify terminalattributes in different ways.  Severaldifferent terminal interfaces exist to provide standardcompliant terminal control..PP.B "Terminal Interface Definitions".spThe.MS tty 4reference pagedescribes the standard Berkeley terminal interface. This interface is backward compatible with earlier versions of the ULTRIX operating system..spThe.MS termio 4reference pagedescribes the terminal interface as defined by theSystem V Interface Definition.  .spThe.MS termios 4reference pagedescribes the termios termio interface as defined by the IEEEP1003 POSIX specification..PPFunctionally, the three terminal interfaces are quite similar.  Major differences lie in how terminal attributes are specified. This includesthe use of different data structures to represent terminal attributes, aswell as the means of setting and receiving attributes..PPIt is possible to use combinations of the three terminal interface definitions.  Under these circumstances, the attributes of oneinterface are mapped into the corresponding attributes of the otherinterfaces.  Combining aspects of different interfaces is discouraged,because it prevents the development of portable programs.For example, a program intended for use with the System V termioterminal interface fails to be a standard compliant program if itsets terminal attributes that are specific toeither of the other two terminalinterfaces..PPCombinations of the different terminal interfaces should be used withextreme caution to avoid unwanted side-effects.  For example, a program mayhave initially set up its terminal environment using the System V termio interface,.MS termio 4 .Suppose that the initial line settings are seven bits even parity with input andoutput processing performed.  If this same program were to set the line toRAW mode as specified in.MS tty 4 ,the line would be set to eight bits no parity, with no input or output processing.These settings would be reflected in the parameters as specified in.MS termio 4 .This simple example is meant to illustrate the subtle side effects that canresult from the use of combinations of terminal interfaces..PPUsing combinations of terminal interfaces can also cause problems ifattributes that are not common to all interfaces are used.  For example,the Berkeley terminal interface allows the user to set the value of thestart and stop characters.  The System V termio interface defines that thestart and stop characters shall be Control-Q and Control-S.  As a result, ifa terminal changes the start and stop characters using the Berkeleyterminal interface, those characters are reset if the terminal parameters are set using the System V termio interface..sp.B "Terminal Interface Usage".br.spThe three interfaces have been developed to provide standard compliant terminal behavior.  The interface type should be specified atthe time of program compilation.  As described in.MS cc 1 ,to compile a System V\-compliant program, the \-Y option (or setting PROG_ENVequal to SYSTEM_FIVE) should be used.  Similarly, the \-YPOSIX option shouldbe used to compile a POSIX\-compliant program.  Without the \-Y or \-YPOSIXcompile option, the program intends to use the Berkeley terminal interface.  Refer to .MS intro 2for specific details on compatibility modes..sp 1.SH Berkeley Terminal Interface.NXR "terminal interface".NXA "tty keyword" "terminal interface".NXA "terminal interface" "bk line discipline".NXA "terminal" "Hazeltine terminal".PP.B Line Disciplines..NXR "terminal interface" "line disciplines".PPThe system provides different.I "line disciplines"for controlling communications lines.In this version of the system, there are several disciplines available:.IP "old" 8The old (Version 7) terminal driver.This is sometimes used when using thestandard shell.MS sh 1and for compatibility with other standard Version 7 UNIX systems..IP "new"The standard terminal driver, with features for job control.  This must be used when using .MS csh 1 ..IP "net"A line discipline used for networking and loading data intothe system over communications lines.  It allows high speed inputat low overhead and is described in .MS bk 4 ..IP "termio"This line discipline is intended for use by System V programs thatuse the termio interface, as described in.MS termio 4 .The termio line discipline is also used by programs that require aPOSIX IEEE P1003 termios interface as described in.MS termios 4 ..PPLine discipline switching is accomplished with the TIOCSETD .PN ioctl:.PP.B "int ldisc = LDISC; ioctl(filedes, TIOCSETD, &ldisc);".PPLDISC is OTTYDISC for the standard tty driver,NTTYDISC for the newdriver, NETLDISC for the networking discipline,and TERMIODISC for System V termio and POSIX termios.The standard tty driver is discipline 0 by convention.Other disciplines may exist for special purposes.The current line discipline can be obtained with the TIOCGETD ioctl.Pending input is discarded when the line discipline is changed..PPAll of the low-speed asynchronouscommunications ports can use anyof the available line disciplines, no matter whathardware is involved.The remainder of this section discusses theold and new disciplines..PP.B "The Control Terminal".NXR "terminal interface" "control terminals and".PPWhen a terminal file is opened, it causes the process to wait until aconnection is established.  In practice, user programs seldom openthese files; they are opened by.MS getty 8or.MS rlogind 8cand become a user's standard input and output file..PPIf a process that has no control terminal opens a terminal file, thenthat terminal file becomes the control terminal for that process.The control terminal is thereafter inherited by a child process during a.MS fork 2 ,even if the control terminal is closed..PPThe file .PN /dev/ttyis, in each process, a synonym for a.I "control terminal"associated with that process.  It is useful for programs that want tobe sure of writing messages on the terminal, no 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..PPA process can remove the association ithas with its controlling terminal by opening the file .PN /dev/ttyand issuing:.IP\fBioctl(fildes, TIOCNOTTY, 0)\fR.PPThis is often desirable in server processes..PP.B "Process Groups".NXR "process group" "associating with terminal".PPCommand processors such as .MS csh 1can arbitrate the terminal between different.I jobsby placing related jobs in a single process group and associating thisprocess group with the terminal.  A terminal's associated process groupmay be set using the TIOCSPGRP .MS ioctl 2 :.IP\fBioctl(fildes, TIOCSPGRP, &pgrp)\fR.PPThe process group can be examined usingusing TIOCGPGRP, rather than TIOCSPGRP, returning the currentprocess group in.I pgrp.The new terminal driver aids in this arbitration by restricting accessto the terminal by processes that are not in the current process group;see.B "Job Access Control.".PP.B "Modes".NXR "terminal" "modes".PPThe terminal drivers have three major modes, characterized by theamount of processing on the input and output characters:.IP cooked 10.NXR "cooked mode" "defined"The normal mode.In this mode, lines of input are collected and input editingis done.The edited line is made available when it is completed bya newline or when the.I t_brkc character (normally undefined) or.I t_eofc character (normally an EOT, CTRL/D) is entered.A carriage return is usually made synonymous with newline in this modeand replaced with a newline whenever it is typed.All driver functions(input editing, interrupt generation,output processing such as delay generation and tab expansion, andso forth) are available in this mode..IP CBREAK 10.NXR "CBREAK mode" "defined"This mode eliminates the character, word, and line editing input facilities,making the input character available to the user program as it is typed.Flow control, literal-next, andinterrupt processing are still done in this mode.Output processing is done..IP RAW 10.NXR "RAW mode" "defined"This mode eliminates all input processing and makes all input charactersavailable as they are typed; no output processing is done either..PPThe style of input processing can also be different whenthe terminal is put in nonblocking I/O mode. For further information, see the FNDELAY flag described in.MS fcntl 2 .In this case, a .MS read 2from the control terminal never blocks.  Rather, it returnsan error indication (EWOULDBLOCK), if there is noinput available..PPA process may also request a SIGIO signal be sent it whenever inputis presentand also whenever output queues fall below the low-water mark.To enable this mode, the FASYNC flag should be set using.MS fcntl 2 ..PP.B "Input Editing".NXR "terminal" "editing input".PPAn ULTRIX terminal ordinarily operates 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.This limit is 256 characters.In RAW mode, the terminaldriver throws away all input and output without noticewhen the limit is reached.In CBREAK mode or cooked mode, it refuses to accept any further input and, ifin the new line discipline, rings the terminal bell..PPInput characters are normally accepted in either even or odd parity,with the parity bit being stripped off before the character is given tothe program.  By clearing either the EVEN or ODD bit in the flags word, it is possible to have input characterswith that parity discarded (see the \fBSummary\fR)..PPIn all of the line disciplines, it is possible to simulate terminalinput using the TIOCSTI ioctl, which takes, as its third argument,the address of a character.  The system pretends that this characterwas typed on the argument terminal,which must be the control terminal, exceptfor the superuser. (This call is not in standard Version 7 UNIX.).PPInput characters are normally echoed by putting them in an output queueas they arrive.  This may be disabled by clearing the ECHO bit in theflags word using the.MS stty 3call or the TIOCSETN or TIOCSETP ioctl(see the \fBSummary\fR)..PPIn cooked mode, terminal input is processed in units of lines.A program attemptingto read is normally suspended until an entire line has beenreceived(but, see the description of SIGTTIN in \fBJob Access Control\fR and FIONREAD in \fBSummary of modes\fR.)No matter how many characters are requestedin the read call, at most one line is returned.It is not, however, necessary to read a whole line atonce; any number of characters can berequested in a read, even one, without losing information..PPDuring input, line editing is normally done, with the erase character .I sg_erase(by default, the number sign (#))logically erasing the last character typed and the .I sg_killcharacter (by default, the at sign (@))logically erasing the entire current input line.These are often reset on CRTs,with CTRL/H replacing the number sign (#),and CTRL/U replacing the at sign (@).These charactersnever erase beyond the beginning of the current input line or an EOF.These characters may be entered literally, bypreceding them with a backslash (\e\|). In the old Teletype driver, both the backslash (\e\|) andthe character entered literally appear on the screen; in the newdriver, the (\e\|) normally disappears..PPThe drivers normally treat eithera carriage return or a newline characteras terminating an input line,replacing the return with a newline and echoinga return and a line feed.If the CRMOD bit is cleared in the local mode word, then the processingfor carriage return is disabled, and it is simply echoed as a returnand does not terminate cooked mode input..PPIn the new driver, there is a literal-next character (normally CTRL/V), which can be typedin both cooked and CBREAK mode preceding anycharacter to prevent its special meaning to the terminal handler. This is to be preferred to theuse of the backslash (\e\|) escaping erase andkill characters, but the backslash (\e\|) is retained with itsold function in the new driver for historical reasons..PPThe new terminal driver also provides two other editing characters innormal mode.  The word-erase character, normally CTRL/W, erases the precedingword, but not any spaces before it.  For the purposes of CTRL/W, a wordis defined as a sequence of nonblank characters, with tabs counted asblanks.Finally, the reprint character,normally CTRL/R, retypes the pending input beginningon a new line.Retyping occurs automatically in cooked mode, if charactersthat would normally be erased from the screen are fouled by program output..PP.B "Input Echoing and Redisplay".NXR "terminal" "echoing input".PPIn the old terminal driver,the erase character is simply echoed.  When a kill characteris typed, it is echoed, followed by a newline (even if the character isnot killing the line, because it was preceded by a backslash (\e\|).).PPThe new terminal driver has several modes for handling the echoing ofterminal input, controlled by bits in a local mode word..PP.I "Hardcopy terminals."When a hardcopy terminal is in use, the LPRTERA bit is normally set inthe local mode word.  Characters that are logically erased arethen printed out backwards,preceded by a backslash (\e\|) and followed by a slash (/) in this mode..PP.I "CRT terminals"When a CRT terminal is in use, theLCRTBS bit is normally set in the localmode word.  The terminal driver echoes the proper number of erasecharacters when input is erased. In the normal case, where the erasecharacter is a CTRL/H, this causes the cursor of the terminal to back upto where it was before the logically erased character was typed.If the input has become fouled due to interspersed asynchronous output,the input is automatically retyped..PP.I "Erasing characters from a CRT"When a CRT terminal is in use, the LCRTERA bit can be set to cause

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?