📄 tty.4
字号:
.\" Copyright (c) 1991, 1992, 1993.\" The Regents of the University of California. All rights reserved..\".\" Redistribution and use in source and binary forms, with or without.\" modification, are permitted provided that the following conditions.\" are met:.\" 1. Redistributions of source code must retain the above copyright.\" notice, this list of conditions and the following disclaimer..\" 2. Redistributions in binary form must reproduce the above copyright.\" notice, this list of conditions and the following disclaimer in the.\" documentation and/or other materials provided with the distribution..\" 3. All advertising materials mentioning features or use of this software.\" must display the following acknowledgement:.\" This product includes software developed by the University of.\" California, Berkeley and its contributors..\" 4. Neither the name of the University nor the names of its contributors.\" may be used to endorse or promote products derived from this software.\" without specific prior written permission..\".\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION).\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF.\" SUCH DAMAGE..\".\" @(#)tty.4 8.3 (Berkeley) 4/19/94.\".Dd August 14, 1992.Dt TTY 4.Os BSD 4.Sh NAME.Nm tty.Nd general terminal interface.Sh SYNOPSIS.Fd #include <sys/ioctl.h>.Sh DESCRIPTIONThis section describes the interface to the terminal driversin the system..Ss Terminal Special FilesEach hardware terminal port on the system usually has a terminal special devicefile associated with it in the directory ``/dev/'' (forexample, ``/dev/tty03'').When a user logs intothe system on one of these hardware terminal ports, the system has alreadyopened the associated device and prepared the line for normal interactiveuse (see.Xr getty 8 .)There is also a special case of a terminal file that connects not toa hardware terminal port, but to another program on the other side.These special terminal devices are called.Em ptysand provide the mechanism necessary to give users the same interface to thesystem when logging in over a network (using.Xr rlogin 1 ,or.Xr telnet 1for example.) Even in these cases the details of how the terminalfile was opened and set up is already handled by special softwarein the system.Thus, users do not normally need to worry about the details ofhow these lines are opened or used. Also, these lines are often usedfor dialing out of a system (through an out-calling modem), but againthe system provides programs that hide the details of accessingthese terminal special files (see.Xr tip 2 .).PpWhen an interactive user logs in, the system prepares the line tobehave in a certain way (called a.Em "line discipline" ) ,the particular details of which is described in.Xr stty 1at the command level, and in.Xr termios 4at the programming level. A user may be concerned with changingsettings associated with his particular login terminal and should referto the preceding man pages for the common cases. The remainder ofthis man page is concernedwith describing details of using and controlling terminal devicesat a low level, such as that possibly required by a program wishingto provide features similar to those provided by the system..Ss Line disciplinesA terminal file is used like any other file in the system in thatit can be opened, read, and written to using standard systemcalls. For each existing terminal file, there is a software processing modulecalled a.Em "line discipline"is associated with it. The.Em "line discipline"essentially glues the low level device driver code with the highlevel generic interface routines (such as.Xr read 2and.Xr write 2 ),and is responsible for implementing the semantics associatedwith the device. When a terminal file is first opened by a program,the default.Em "line discipline"called the.Dv termiosline discipline is associated with the file. This is the primaryline discipline that is used in most cases and provides the semanticsthat users normally associate with a terminal. When the.Dv termiosline discipline is in effect, the terminal file behaves and isoperated according to the rules described in.Xr termios 4 .Please refer to that man page for a full description of the terminalsemantics.The operations described heregenerally represent features commonacross all.Em "line disciplines" ,however some of these calls may notmake sense in conjunction with a line discipline other than.Dv termios ,and some may not be supported by the underlyinghardware (or lack thereof, as in the case of ptys)..Ss Terminal File OperationsAll of the following operations are invoked using the.Xr ioctl 2system call. Refer to that man page for a description ofthe.Em requestand.Em argpparameters.In addition to the ioctl.Em requestsdefined here, the specific line disciplinein effect will define other.Em requestsspecific to it (actually.Xr termios 4defines them as function calls, not ioctl.Em requests . )The following section lists the available ioctl requests. Thename of the request, a description of its purpose, and the typed.Em argpparameter (if any)are listed. For example, the first entry says.Pp.D1 Em "TIOCSETD int *ldisc".Ppand would be called on the terminal associated withfile descriptor zero by the following code fragment:.Bd -literal int ldisc; ldisc = TTYDISC; ioctl(0, TIOCSETD, &ldisc);.Ed.Ss Terminal File Request Descriptions.Bl -tag -width TIOCGWINSZ.It Dv TIOCSETD Fa int *ldiscChange to the new line discipline pointed to by.Fa ldisc .The available line disciplines are listed in.Pa Aq sys/termios.hand currently are:.Pp.Bl -tag -width TIOCGWINSZ -compact.It TTYDISCTermios interactive line discipline..It TABLDISCTablet line discipline..It SLIPDISCSerial IP line discipline..El.Pp.It Dv TIOCGETD Fa int *ldiscReturn the current line discipline in the integer pointed to by.Fa ldisc ..It Dv TIOCSBRK Fa voidSet the terminal hardware into BREAK condition..It Dv TIOCCBRK Fa voidClear the terminal hardware BREAK condition..It Dv TIOCSDTR Fa voidAssert data terminal ready (DTR)..It Dv TIOCCDTR Fa voidClear data terminal ready (DTR)..It Dv TIOCGPGRP Fa int *tpgrpReturn the current process group the terminal is associatedwith in the integer pointed to by.Fa tpgrp .This is the underlying call that implements the.Xr termios 4.Fn tcgetattrcall..It Dv TIOCSPGRP Fa int *tpgrpAssociate the terminal with the process group (as an integer) pointed to by.Fa tpgrp .This is the underlying call that implements the.Xr termios 4.Fn tcsetattrcall..It Dv TIOCGETA Fa struct termios *termPlace the current value of the termios state associated with thedevice in the termios structure pointed to by.Fa term .This is the underlying call that implements the.Xr termios 4.Fn tcgetattrcall..It Dv TIOCSETA Fa struct termios *termSet the termios state associated with the device immediately.This is the underlying call that implements the.Xr termios 4.Fn tcsetattrcall with the.Dv TCSANOWoption..It Dv TIOCSETAW Fa struct termios *termFirst wait for any output to complete, then set the termios stateassociated with the device.This is the underlying call that implements the.Xr termios 4.Fn tcsetattrcall with the.Dv TCSADRAINoption..It Dv TIOCSETAF Fa struct termios *termFirst wait for any output to complete, clear any pending input,then set the termios state associated with the device.This is the underlying call that implements the.Xr termios 4.Fn tcsetattrcall with the.Dv TCSAFLUSHoption..It Dv TIOCOUTQ Fa int *numPlace the current number of characters in the output queue in theinteger pointed to by.Fa num ..It Dv TIOCSTI Fa char *cpSimulate typed input. Pretend as if the terminal received thecharacter pointed to by.Fa cp ..It Dv TIOCNOTTY Fa voidThis call is obsolete but left for compatibility. In the past, whena process that didn't have a controlling terminal (see.Em The Controlling Terminalin.Xr termios 4 )first opened a terminal device, it acquired that terminal as itscontrolling terminal. For some programs this was a hazard as theydidn't want a controlling terminal in the first place, and thisprovided a mechanism to disassociate the controlling terminal fromthe calling process. It.Em mustbe called by opening the file.Pa /dev/ttyand calling.Dv TIOCNOTTYon that file descriptor..PpThe current system does not allocate a controlling terminal toa process on an.Fn opencall: there is a specific ioctl called.Dv TIOSCTTYto make a terminal the controllingterminal.In addition, a program can.Fn forkand call the.Fn setsidsystem call which will place the process into its own session - whichhas the effect of disassociating it from the controlling terminal. Thisis the new and preferred method for programs to lose their controllingterminal..It Dv TIOCSTOP Fa voidStop output on the terminal (like typing ^S at the keyboard)..It Dv TIOCSTART Fa voidStart output on the terminal (like typing ^Q at the keyboard)..It Dv TIOCSCTTY Fa voidMake the terminal the controlling terminal for the process (the processmust not currently have a controlling terminal)..It Dv TIOCDRAIN Fa voidWait until all output is drained..It Dv TIOCEXCL Fa voidSet exclusive use on the terminal. No further opens are permittedexcept by root. Of course, this means that programs that are run byroot (or setuid) will not obey the exclusive setting - which limitsthe usefulness of this feature..It Dv TIOCNXCL Fa voidClear exclusive use of the terminal. Further opens are permitted..It Dv TIOCFLUSH Fa int *whatIf the value of the int pointed to by.Fa whatcontains the.Dv FREADbit as defined in.Pa Aq sys/file.h ,then all characters in the input queue are cleared. If it containsthe.Dv FWRITEbit, then all characters in the output queue are cleared. If thevalue of the integer is zero, then it behaves as if both the.Dv FREADand.Dv FWRITEbits were set (i.e. clears both queues)..It Dv TIOCGWINSZ Fa struct winsize *wsPut the window size information associated with the terminal in the.Va winsizestructure pointed to by.Fa ws .The window size structure contains the number of rows and columns (and pixelsif appropriate) of the devices attached to the terminal. It is set by user softwareand is the means by which most full\&-screen oriented programs determine thescreen size. The.Va winsizestructure is defined in.Pa Aq sys/ioctl.h ..It Dv TIOCSWINSZ Fa struct winsize *wsSet the window size associated with the terminal to be the value inthe.Va winsizestructure pointed to by.Fa ws(see above)..It Dv TIOCCONS Fa int *onIf.Fa onpoints to a non-zero integer, redirect kernel console output (kernel printf's)to this terminal.If.Fa onpoints to a zero integer, redirect kernel console output back to the normalconsole. This is usually used on workstations to redirect kernel messagesto a particular window..It Dv TIOCMSET Fa int *stateThe integer pointed to by.Fa statecontains bits that correspond to modem state. Following is a listof defined variables and the modem state they represent:.Pp.Bl -tag -width TIOCMXCTS -compact.It TIOCM_LELine Enable..It TIOCM_DTRData Terminal Ready..It TIOCM_RTSRequest To Send..It TIOCM_STSecondary Transmit..It TIOCM_SRSecondary Receive..It TIOCM_CTSClear To Send..It TIOCM_CARCarrier Detect..It TIOCM_CDCarier Detect (synonym)..It TIOCM_RNGRing Indication..It TIOCM_RIRing Indication (synonym)..It TIOCM_DSRData Set Ready..El.PpThis call sets the terminal modem state to that represented by.Fa state .Not all terminals may support this..It Dv TIOCMGET Fa int *stateReturn the current state of the terminal modem lines as representedabove in the integer pointed to by.Fa state ..It Dv TIOCMBIS Fa int *stateThe bits in the integer pointed to by.Fa staterepresent modem state as described above, however the state is OR-edin with the current state..It Dv TIOCMBIC Fa int *stateThe bits in the integer pointed to by.Fa staterepresent modem state as described above, however each bit which is onin.Fa stateis cleared in the terminal..El.Sh SEE ALSO.Xr getty 8 ,.Xr ioctl 2 ,.Xr pty 4 ,.Xr stty 1 ,.Xr termios 4
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -