termios.4
来自「<B>Digital的Unix操作系统VAX 4.2源码</B>」· 4 代码 · 共 1,622 行 · 第 1/4 页
4
1,622 行
.TH termios 4.SH Nametermios \- POSIX terminal interface.SH Description.NXR "terminal interface".SH Interface CharacteristicsThe POSIX terminal interface is provided tocontrol asynchronous communications ports, pseudoterminals, and the specialfile,.PN /dev/tty .The ULTRIX operating system also provides a SVID termioterminal interface as defined in .MS termio 4and a Berkeley terminal interface as defined in .MS tty 4 .The following sections describe the general terminal interface as definedby the POSIX operating system specification.For a general overview of the variousterminal interfaces, refer to the subsection entitled Terminal interface definitions in .MS tty 4 ..PPThe POSIX termios specification defines a set of terminal-relatedfunctions and attributes that facilitate the development of portable programs. The specificationallows for local extensions to the terminal interface. Throughout this description, all local extensions to the termios interface are noted.Programs that are written to be highly portable should avoid the usage oflocal extensions..SH Opening a Terminal Device FileWhen a terminal file is opened, it normally causes the process to wait untila connection is established. In practice, application programs seldom open these files; they are opened by special programs such as .MS getty 8and become a user's standard input, output, and error files..PPAs described in .MS open 2 ,opening a terminal device file with the O_NONBLOCKflag clear causes the process to block until the terminal device is readyand available.If CLOCAL mode is not set, blocking occurs until a connection is established.If CLOCAL mode is set, or the O_NONBLOCK flag is specified in the.MS open 2 ,the.MS open 2returns a file descriptor, without waiting for a connection to be established..SH Process GroupsA terminal may have a foreground process group associated with it. Thisforeground process group plays a special role in handling signal-generatinginput characters, as discussed in the Special Characters description..PPA command interpreter that is capable ofsupporting job control,.MS csh 1for example,can allocate the terminal to different jobsor process groups by placing related processes in a single process group andassociating this process group with the terminal.A terminal's foregroundprocess group can be set or examined by a process with sufficient privileges.The terminal interface aids in this allocation by restricting access to theterminal by processes that are not in the foreground process group. See the JobAccess Control description for more information..SH The Controlling TerminalA terminal can belong to a process as its controlling terminal. Each process of a session that has a controlling terminal has the samecontrolling terminal. A terminal may be the controlling terminal for at mostone session. If a session leader has no controlling terminal and opens a terminal device file that is not already associated with a session, without using the O_NOCTTY .MS open 2flag, the terminal then becomes the controlling terminal of the session leader.If a process that is not a session leader opens a terminal file, or theO_NOCTTY option is used with .MS open 2 ,that terminal cannot become the controlling terminal of the callingprocess. When a controlling terminal becomes associated with a session, itsforeground process group is set to the process group of the session leader..PPThe controlling terminal is inherited by a child process during a .MS fork 2function. A process relinquishes its controlling terminal when it creates a new session with the .MS setsid 2function, or when all file descriptors associated with the controlling terminalhave been closed..PPWhen a controlling processterminates, the controlling terminalis disassociated from the current session,allowingthe terminal to be acquired as a controlling terminal by a new session process group leader.Subsequent access to the terminal by other processes in the earlier sessionmay be denied, with attempts to access the terminal treated as if a modem disconnect had been sensed..SH Closing a Terminal Device FileWhen the last process that has the terminal line open closes the terminalline, the process waits for all output to clear and any input is discarded. The wait does not exceed four minutes, preventing the line from becoming hung if a progress isnot made in the final output. After the final output has been transmitted, anypending input is flushed. If HUPCL is set in the control modes, and thecommunications port supports a disconnect function, the terminal device performs a disconnect..SH Modem DisconnectWhen a modem disconnect is detected by the terminal interfacefor a controlling terminal, and the CLOCAL bit is not set in the control flag, the SIGHUP signalis sent to all the controlling processes associated with theterminal. Unless other arrangements have been made, this signal causes thecontrolling processes to terminate. If SIGHUP is ignored or caught, any subsequent readreturns with an end-of-file indication. Thus, programs that read a terminal file and test for end-of-file can terminate appropriately after a disconnect.Any subsequent .MS write 2to the terminal device returns \-1 with .I errno set to [EIO], until the deviceis closed..SH Terminal Access ControlIf a process is in the foreground process group (nonzero) of itscontrolling terminal (that is, if the process is a foreground process),.MS read 2operations are allowed as described in the Input Processingand Reading Characters description. Any attempts by a process in a background process group to read from itscontrolling terminal causes its process group to receive a SIGTTINsignal, unless one of the following is true: .IP \(bu 5If the reading process is ignoring or blocking the SIGTTIN signal..IP \(bu 5If the process group of the reading process is orphaned, the.MS read 2returns \-1, with .I errno set to [EIO], and no signal is sent..PPAttempts by a process in a background process group to write to its controlling terminal causes the process group to receive a SIGTTOUsignal, unless one of the following is true:.IP \(bu 5If TOSTOP is not set, or if TOSTOP is set and the process is ignoring or blocking the SIGTTOU signal, the process is allowed to write to the terminal and the SIGTTOU is not sent. .IP \(bu 5If TOSTOP is set, and the processgroup of the writing process is orphaned, and the writing process is notblocking SIGTTOU, the.MS write 2returns \-1, with .I errno set to [EIO], and no signal is sent..PPCertain calls that set terminal parameters are treated in the same fashionas.MS write 2 ,except that TOSTOP is ignored. That is, the effect is identical to that ofterminal writes when TOSTOP is set.See the Control Functions descriptionfor more information..SH Input Processing and Reading CharactersA terminal device associated with a terminal device file operates in full-duplex mode, so that characters can arrive while output is occurring.Each terminal device file has associated with it an input queue, in whichincoming characters are stored by the system before being read by a process.The system imposes a limit (MAX_INPUT), on the number of bytes that can bestored in the input queue. MAX_INPUT is limited to 256 characters.When ICANON is not set andthe system's character input buffers become full, the input buffer isflushed without notice. This causes all the characters in the input queueto be lost. If ICANON is set and the system's character input buffers become full, the driver discards additional characters and echos a bell(ASCII BEL) to notify the user of the full condition..PPDepending on whether or not the terminal device is in canonical mode or noncanonical mode, two general types of input processing are available.See the Canonical Mode Input Processing and NoncanonicalMode Input Processing descriptions for more information.Additionally, input characters are processedaccording to the c_iflag and c_lflag fields. See the Input Modes and LocalModes descriptions.Such processing can include echoing, which, in general, means transmitting inputcharacters immediately back to the terminal when they are received from theterminal. This is useful for terminals that can operate in full-duplex mode.The manner in which characters are provided to a process reading from a terminal device is dependent on whether the terminal file is in canonicalor noncanonical mode..PPAnother dependency is whether or not the O_NONBLOCK is set by .MS open 2 or .MS fcntl 2 . If the O_NONBLOCK flag is clear, then the read requestis blocked until data is available or a signal has been received. If the O_NONBLOCK flag is set, then the read request completes, without blocking, in one of the following ways:.IP \(bu 5If there is enough data available to satisfy the entire request,the read completes successfully and returns the number of bytes read..IP \(bu 5If there is not enough data available to satisfy the entire request,the read completes successfully, having read as much data aspossible and returns the number of bytes it was able to read..IP \(bu 5If data is not available, the read returns a \-1, with.I errno set to EAGAIN..PPAs stated previously, the availability of data is dependent onthe input processing mode. The input processing mode can be eithercanonical or non-canonical. The following sections discussthese modes in detail..SH Canonical Mode Input ProcessingIn canonical mode input processing, terminal input is processed in units oflines. A line is delimited by a new-line (\\n) character (ASCII LF),an end-of-file character (ASCII EOF), or a user-defined end-of-line character (EOL) .See the description of Special Characters for more information on EOF and EOL..PPA read request cannot be satisfied until anentire line has been typed or a signal has been received. Regardless ofthe number of characters requested in the read call, at most one line isreturned. However, it is not necessary to read a whole line at once; oneor more characters can be requested in a read without losing information..PPMAX_CANON (256) defines the maximum number of input characters the systemcan buffer in canonical mode. When this limit is exceeded, the system discards additional input..PPErase and kill processing occur when either the ERASE or KILL characteris received. This processing affects data in theinput queue that has not been delimited by a new-line (NL), end-of-file(EOF), or end-of-line (EOL) character. The data that is not delimited creates the current line. The ERASE character deletes the last character in the current line, if there is any.The KILL character deletes all data in the current line, if there is any.The ERASE and KILL characters have no effect if there is no data in the current line.The ERASE and KILL characters themselves are not placed in the input queue..PPThe reprint (RPRNT) character retypes pending input beginning on a newline. Retyping is automatic, if characters that would normallybe erased from the screen are interspersed with program output..SH Noncanonical Mode Input ProcessingIn noncanonical mode input processing, input characters are not assembled intolines, and erase and kill processing do not occur. The values of the specialcharacters MIN and TIME are used to determine how to process the charactersreceived. MIN and TIME are defined by the c_cc array of special controlcharacters..PPMIN represents the minimum number of characters that should be received whenthe read is satisfied (for example, the characters are returned to the user).TIME is a timer of 0.1 second granularity that is used to time out bursty and short term data transmissions. If MIN is greater than MAX_INPUT (256), the value of MIN is truncated to be MAX_INPUT. The four possible values for MIN and TIME and examples of their interactions are as follows:.PP1.MIN > 0, TIME > 0..brIn this case, TIME serves as an intercharacter timer and is activated after the first character is received. Because it is an intercharacter timer, it is reset after a character is received. The interaction between MIN and TIME provokes the intercharacter time to start as soon as one character is received. If MIN characters are received before the intercharacter timer expires, the read is satisfied. .PPIf the timer expires before MIN characters are received, the characters receivedto that point are returned to the user. If TIME expires, at least one character is returned, because the timer would not have been enabled unlessa character was received. The read blocks until the MIN and TIME mechanisms are activated by the receipt of the first character, or a signal is received..PP2.MIN > 0, TIME = 0..brIn this case, the value of TIME is zero, the timer is inactive. However,MIN is significant. A pending read is not satisfied until MIN characters or a signal are received. That is, the pending read sleeps until MIN charactersare received. A program that uses this example to read record-based terminal I/O can indefinitely block the read operation..PP3.MIN = 0, TIME > 0..brIn this case, because MIN = 0, TIME does not represent an intercharactertimer. Instead, it serves as a read timer that is activated as soon as the .MS read 2function is processed.A read is satisfied as soon as a single character is receivedor the read timer expires. Note, if the timer expires, acharacter is not returned. If the timer does not expire, a read is onlysatisfied if a character is received. For example, the readcannot block indefinitely waiting for a character. If a character is notreceived within TIME*0.1 seconds after the read is initiated, the read returns a value of zero, having read no data..PP4.MIN = 0, TIME = 0..brIn this case, only the minimum number of characters requested or the number of characters currently available are returned without waiting for more characters to be input. In this example, the return is immediate..PPThe following list summarizes the previous examples:.IP \(bu 5The interactions of MINand TIME are not symmetric. For example, when MIN > 0 and TIME = 0,TIME has no effect. However, if MIN = 0 and TIME > 0, MIN is activated by the receipt of a single character..IP \(bu 5When MIN > 0 and TIME > 0, TIME represents an intercharactertimer; when MIN = 0, TIME > 0, TIME represents a read timer..PPThe previous summary highlights the dual purpose of the MIN and TIME feature. Cases 1 and 2 handle burst mode activity (suchas file transfer programs) where a program would like to process at least MIN characters at atime. In case 1, the intercharacter timer is activated by a user as a safety precaution. However, in case 2, it is turned off. .PPCases 3 and 4 exist to handle single character timed transfers. These examples are readily adaptable to screen-based applications that need to know if a character is present in the input queue before refreshing the screen. In case 3, the read is timed. However, in case 4, it is not..PPNote that MIN is always a minimum. It does not denotea record length. That is, if a program performs a read of 20 bytes, MINhas a value of 10, and there are 25 characters present, 20 charactersare returned to the user..SH Writing Characters and Output ProcessingWhen a process writes one or more characters to a terminal device file, they are processed according to the c_oflag (see Output Modes).The terminal interface provides a buffering mechanism. For example,when a call to .MS write 2completes, allof the characters written have been scheduled for transmission to the device,but the transmission is not necessarily complete. The characters aretransmitted to the terminal as soon as previously written charactershave output successfully..SH Signal HandlingSignals caught during a .MS read 2 ,.MS write 2 ,or other operation on the file descriptorassociated with the terminal file are handled appropriately, as described in.MS signal 3 ..SH Special CharactersCertain characters have special functions on input or output.These functions are:.IP "\fBINTR\fR" 11Special character on input that is recognized if the ISIG flagis enabled. Generates a SIGINT signal that is sent to all processes in the foreground process group associated withthe terminal. If ISIG is set, the INTR character is discarded when processed.The default value is octal 0177..IP "\fBQUIT\fR" Special character on input that is recognized if the ISIG flagis enabled. Generates a SIGQUIT signal that is sent to allprocesses in the foreground process group associated withthe terminal. If ISIG is set, the QUIT character is discarded when processed.The default value is CTRL/| (ASCII FS)..IP "\fBERASE\fR" Special character on input that is recognized if the ICANON flag is set. Erases the last character in the current line. It cannoterase beyond the start of a line, as delimited by an NL, EOF,or EOL character. If ICANON is set, the ERASE character is discarded when processed.The default value is the number sign (#)..IP "\fBKILL\fR" Special character on input that is recognized if the ICANON flagis set. Deletes the entire line, as delimited by an NL, EOF, orEOL character. If ICANON is set, the KILL character is discarded when processed.The default value is the at sign (@)..IP "\fBEOF\fR" Special character on input that is recognized if the ICANON flagis set. This character is used to generate an end of file (EOF)from the terminal. When received, all the characters waiting to be read areimmediately passed to the program, without waiting for a newline,and the EOF is discarded. Thus, if there are no characterswaiting (that is, if the EOF occurred at the beginning of a line),a byte count of zero is returned from .MS read 2 ,representing an end-of-file indication. If ICANON is set, the EOF character is discarded when processed.The default value is CTRL/D (ASCII EOT)..IP "\fBNL\fR" Special character on input that is recognized if the ICANON flagis set. It is the assigned line delimiter (\\n). It cannot be
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?