tty.4
来自「<B>Digital的Unix操作系统VAX 4.2源码</B>」· 4 代码 · 共 1,190 行 · 第 1/3 页
4
1,190 行
input to be erased from thescreen with a \*(lqbackspace-space-backspace\*(rqsequence when character- or word-deleting sequences are used.LCRTERA must be used with LCRTBS for this functionality.A LCRTKIL bit can be set as well, causing the input tobe erased in this manner on line kill sequences as well..PP.I "Echoing of control characters"If the LCTLECH bit is setin the local state word, then nonprinting (control)characters are normally echoed as \f(CW^\fIx\fR(where \fIx\fP is the character used in combination with the CTRL key),rather than being echoed unmodified; delete is echoed as .PN ^? ..PPThe normal modes for using the new terminal driver on CRT terminalsare speed-dependent.At speeds less than 1200 baud, the LCRTERA and LCRTKILL processingis slow, so .MS stty 1normally just sets LCRTBS and LCTLECH; atspeeds of 1200 baud or greater, all of these bits are normally set.The.PN sttycommand summarizes these option settings and the use of the new terminaldriver as ``newcrt''..PP.B "Output Processing".NXR "terminal interface" "processing output".PPWhen one or morecharacters are written, they are actually transmittedto the terminal as soon as previously written charactershave finished typing.(As noted above, input characters are normally echoed by putting them in the output queueas they arrive.)When a process produces characters more rapidly than they can be typed,it is suspended when its output queue exceeds some limit.When the queue has drained down to some threshold, the program is resumed.Even parity is normally generated on output.The EOT character is not transmitted in cooked mode, to prevent terminalsthat respond to it from hanging up; programs using RAW or CBREAK modeshould be careful..PPThe terminal drivers provide necessaryprocessing for cooked and CBREAK modeoutput including delay generation for certain special characters and paritygeneration. Delays are available after backspaces (CTRL/H), form feeds (CTRL/L), carriage returns (CTRL/M), tabs (CTRL/I), and newlines (CTRL/J).The driver also optionallyexpands tabs into spaces, where the tab stops are assumed to be set everyeight columns.These functions are controlled by bits in the tty flags word.(See \fBSummary\fR.).PPThe terminal drivers provide for mapping between uppercase and lowercaseon terminals lacking lowercase, and for other special processing ondeficient terminals..PPFinally, in the new terminal driver, there is an output flush character,normally CTRL/O, which sets the LFLUSHO bit in the local mode word, causingsubsequent output to be flushed until it is cleared by a program or moreinput is typed.This character has effect in both cooked and CBREAK modesand causes pending input to be retyped if there is any pending input.An ioctl to flush the charactersin the input and output queues, TIOCFLUSH,is also available..PP.B "Uppercase Terminals and Hazeltines".NXR "terminal" "lowercase letters and".PPIf the LCASE bit is set in the tty flags, thenall uppercase letters are mapped intothe corresponding lowercase letter.The uppercase letter may be generated by precedingit by a backslash (\\).If the new terminal driver is being used,then uppercase lettersare preceded by a a backslash (\\) when output.In addition, the following escape sequences can be generatedon output and accepted on input:.PP.nffor \` | ~ { }use \e\|\' \e\|! \e\|^ \e\|( \e\|).fi.PPTo deal with Hazeltine terminals, which do not recognize the tilde (~) asan ASCII character,the LTILDE bit may be set in the localmode word when using the new terminal driver; in this case, the tilde (~)will be replaced with the grave accent (\`) on output..PP.B "Flow Control".NXR "terminal" "suspending output".PPThere are two characters (the stop character, normally CTRL/S, and thestart character, normally CTRL/Q), that cause output to be suspended andresumed respectively. Extra stop characters typed when outputis already stopped have no effect, unless the start and stop charactersare made the same, in which case output resumes..PPA bit in the flags word may be set to put the terminal into TANDEM mode.In this mode, the system produces a stop character (default CTRL/S) whenthe input queue is in dangerof overflowing, and a start character (defaultCTRL/Q) when the input has drained sufficiently. This mode is usefulwhen the terminal is actually another machine that obeys theconventions..PPA bit in the local mode word may be set to put the terminal into AUTOFLOW mode.In this mode, flow control characters are responded to at the hardwarelevel. Upon receipt of a stop character, the hardware suspends output. Thisallows for quick response to the stop character, which prevents buffer overflow (in printers for example). AUTOFLOW functionality is only provided if the start character is CTRL/Q and the stop character isCTRL/S.The AUTOFLOW bit is cleared if the start or stop characters arenot standard values, or if the RAW bit is not set..PP.B "Line Control and Breaks".NXR "terminal" "controlling line".PPThere are several.PN ioctlcalls available to control the state of the terminal line.The TIOCSBRK ioctl sets the break bit in the hardware interface,causing a break condition to exist. This can be cleared by TIOCCBRK, usually after a delay with.MS sleep 3 .Break conditions in the inputare reflected as a null character in RAW modeor as the interrupt character in cooked or CBREAK mode.The TIOCCDTR ioctl clears the data terminal ready condition.It can be set again by TIOCSDTR..PPWhen the carrier signal from the dataset drops (usuallybecause the user has hung up his terminal), aSIGHUP hangup signal is sent to the processes in the distinguishedprocess group of the terminal.This usually causes them to terminate(the SIGHUP can be suppressed by setting the LNOHANG bit in the localstate word of the driver.)Access to the terminal by other processes is then normally revoked,so any further reads fail,and programs that read a terminal and test forend-of-file on their input terminate appropriately..PPWhen using an ACU,it is possible to ask that the phone line be hung up on the last closewith the TIOCHPCL ioctl. This is normally done on the outgoing line..PP.B "Interrupt Characters".NXR "terminal" "interrupt characters".PPThere are several characters that generateinterrupts in cooked and CBREAKmode. All are sent the processes in the control group of the terminal,as if a TIOCGPGRP ioctl were done to get the process group and then a.MS killpg 2system call were done,except that these characters also flush pending input and output whentyped at a terminal(for example, TIOCFLUSH).The characters shown here are the defaults.The field names in the structures are also shown.The characters may be changed,although this is not often done..IP ^?\fBt_intrc\fR (Delete) generates a SIGINT signal.This is the normal way to stop a process that is no longer interesting or to regain control in an interactive program..IP ^\e\fBt_quitc\fR (FS) generates a SIGQUIT signal.This is used to cause a program to terminate and produce a core image,if possible, in the file.B corein the current directory..IP ^Z\fBt_suspc\fR (EM) generates a SIGTSTP signal that is used to suspendthe current process group..IP ^Y\fBt_dsuspc\fR (SUB) generates a SIGTSTP signal as CTRL/Z does, but thesignal is sent when a program attempts to read the CTRL/Y, rather than whenit is typed..PP.B "Job Access Control".NXR "terminal" "controlling job access".PPWhen using the new terminal driver,if a process that is not in the distinguished process group of itscontrol terminal attempts to readfrom that terminal, its process group issent a SIGTTIN signal. This signal normally causes the members ofthat process group to stop. If, however, the process is ignoring SIGTTIN, has SIGTTIN blocked,is an.IR "orphan process" ,or is in the middle of process creation using.MS vfork 2 ,it is returned an end-of-file instead. (An.I "orphan process"is a process whoseparent has exited and that has been inherited by the.MS init 8process.).NXR "orphan process" "defined"Under older UNIX systemsthese processes would typically have had their input files reset to.PN /dev/null ,so this is a compatible change..PPWhen using the new terminal driver with the LTOSTOP bit set in the localmodes, a process is prohibited fromwriting on its control terminal, if it isnot in the distinguished process group for that terminal.Processes that are holding or ignoring SIGTTOU signals, that are orphans, or that are in the middle of a .PN vfork 2 ,are excepted and allowed to produce output..PP.B "Modem Control".NXR "modem" "controlling".PPIoctls have been added to provide more flexible modem control ontty lines. The new commands are summarized below. .NXR "terminal interface" "modem ioctl list".IP TIOCMODEM 15Indicate to the system that this tty line has a modem attached to itand should not ignore modem signals. The argument to this ioctl is the address of a word that containseither zero or a nonzero value.Zero indicates that the effect of the ioctl is temporary,and the line is reset to its condition prior to the ioctl, whenthe tty line is closed.Nonzero indicates that the effect of the ioctl should be permanent.Root privilege is required to effect a permanent change..IP TIOCNMODEMIndicate to the system that modem transmissions should be ignored on this line. This is useful for connections that do not implement thefull RS-232 standard (most direct connections to terminals)..NXR "RS-232 standard" "modems and"The argument to this ioctl is the address of a word that containseither zero or a nonzero value.Zero indicates that the effect of ioctl is temporary,and the line is reset to its condition prior to the ioctl, whenthe tty line is closed.Nonzero indicates that the effect of the ioctl should be permanent.Root privilege is required to effect a permanent change..IP TIOCNCARIgnore soft carrier when doing reads or writes. If carrier is notpresent on a modem line, then reads or writes normally fail.This ioctl allows reads and writes to succeed, regardless of thestate of this line.This is useful for dealing with automatic call units that send statusmessages before carrier is present on the line.The alternative would be to usethe TIOCNMODEM ioctl and ignore all modemsignals and force soft carrier to be present. The latter alternative is not desirable, if full modem control is required..IP TIOCCARThe opposite effect of TIOCNCAR.If carrier is not present on modem lines, then reads and writes fail..IP TIOCWONLINEThis ioctl blocks the process until carrier is detected..PPThe following example demonstrates how one might deal with a modem:.NXR(e) "modem" "setting up".EX 0 /* open the line and don't wait for carrier */ fd = open(dcname, O_RDWR|O_NDELAY); /* we are attached to a modem so don't ignore modem signals */ ioctl(fd, TIOCMODEM, &temp); ioctl(fd, TIOCNCAR); /* ignore soft carr while dialing number */ /* * dial phone number and negotiate with auto call unit. */ ioctl(fd, TIOCCAR); /* don't ignore carrier anymore */ alarm(40); ioctl(fd, TIOCWONLINE); /* wait for carrier */ alarm(0);.EE.PP.B "Shared tty Lines".NXR "terminal" "implementing shared lines".PPThe following ioctls are used by .MS getty 8 ,.MS tip 1 ,and.MS uucp 1to implement shared terminal lines: TIOCSINUSE/FIOSINUSE, TIOCCINUSE/FIOCINUSE.Shared terminal lines can be used for both incoming and outgoingconnections. For further information, see the .I Guide to System Environment Setup. These ioctls can be used by any user process on any file type, butthey do not work on a socket. .IP TIOCSINUSE 15TIOCSINUSE is defined to FIOSINUSE. This command checks to see if the file is marked ``in use''.If the file is not ``in use'', it is marked ``in use'' by the current process and the ioctl succeeds.If the file is already ``in use'' by some otherprocess, the ioctl fails and errno is set to EALREADY. For further information, see .MS open 2 ..IP TIOCCINUSE TIOCCINUSE is defined to FIOCINUSE. This command clears the ``in use'' flag on a file, if the current process wasthe one that set the ``in use'' flag.Any process that is blocked and waiting for the ``in use''flag to clear will be resumed. For further information, see .MS open 2 ..PP.B "Summary of Modes".PPUnfortunately, due to the evolution of the terminal driver,there are four different structures that contain various portions of thedriver data. The first of these (\fBsgttyb\fR)contains that part of the informationlargely common between Version 6 and Version 7 UNIX systems.The second contains additional control characters added in Version 7.The third is a word of local state peculiar to the new terminal driver,and the fourth is another structure of special characters added for thenew driver. .PP.B Basic modes: sgtty \- There are two versions of the sgttyb structure: one for BSD (default)and one for SYSTEM_FIVE. The basic.IR ioctl suse the structuredefined in.PN <sgtty.h> :.NXR "sgttyb file".PPYou get this version of sgttyb if you include .PN <sgtty.h> , into your .c source, and then compilewith `cc \-YBSD ....' or `setenv PROG_ENV BSD' or by default to BSD ifPROG_ENV is not defined, or `\-Y' is not specified..EX 5struct sgttyb { char sg_ispeed; char sg_ospeed; char sg_erase; char sg_kill; short sg_flags;};.EE.PPYou get this version of sgttyb if you include .PN <sgtty.h> in your .c source, and then compile using the `\-Y' or `\-YSYSTEM_FIVE' option of .PN cc ,or set PROG_ENV environment to `SYSTEM_FIVE'..EX 5struct sgttyb { char sg_ispeed; char sg_ospeed; char sg_erase; char sg_kill; int sg_flags;};.EE.PPThe.I sg_ispeed and .I sg_ospeedfields describe the input and output speeds of thedevice according to the following table,which corresponds to thespeeds offered on most Digital terminal multiplexers.If other hardware is used,impossible speed changes are ignored.Symbolic values in the table are as defined in.PN <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 baud
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?