Manual reference pages-tty (4)
Name
Tty-General Terminal interface
Contents
Synopsis
Description
Terminal special files
Line disciplines
Terminal File Operations
Terminal file request descriptions
See also
Synopsis
. In sys/IOCTL. h
Description
This section describes the interface to the terminal drivers in the system.
Terminal special files
Each hardware terminal port on the system usually has a terminal special device file associated with it in the directory ''/dev/'' (for example, ''/dev/tty03 ''). when a user logs into the system on one of these hardware terminal ports, the system has already opened the associated device and prepared the line for normal interactive use (see Getty 8 .) there is also a special case of a terminal file that connects not to a hardware terminal port, but to another program on the other side. these special terminal devices are called ptys and provide the mechanic necessary to give users the same interface to the system when logging in over a network (using rlogin (1), or telnet (1) for example ). even in these cases the details of how the terminal file was opened and set up is already handled by special software in the system. thus, users do not normally need to worry about the details of how these lines are opened or used. also, these lines are often used for dialing out of a system (through an out-calling modem ), but again the system provides programs that hide the details of accessing these terminal special files (see tip (1 )).
When an interactive user logs in, the system prepares the line to behave in a certain way (called a line discipline), the particle details of which is described in stty (1) at the command level, and in termios (4) at the programming level. A user may be concerned with changing settings associated with his maid login terminal and shoshould refer to the preceding man pages for the common cases. the remainder of this man page is concerned with describing details of using and controlling terminal devices at a low level, such as that possibly required by a program wishing to provide features similar to those provided by the system.
Line disciplines
A terminal file is used like any other file in the system in that it can be opened, read, and written to using standard system CILS. for each existing terminal file, there is a software processing module called a line discipline is associated with it. the line discipline essential tially glues the low level device driver code with the high level generic interface routines (such as read (2) and write (2 )), and is responsible for implementing the semantics associated with the device. when a terminal file is first opened by a program, the default line discipline called the termios line discipline is associated with the file. this is the primary line discipline that is used in most cases and provides the semantics that users normally associate with a terminal. when the termios line discipline is in effect, the terminal file behaves and is operated according to the rules described in termios (4 ). please refer to that man page for a full description of the terminal semantics. the Operations described here generally represent features common features SS all line disciplines, however some of these CILS may not make sense in conjunction with a line discipline other than termios, and some may not be supported by the underlying hardware (or lack thereof, as in the case of ptys ).
Terminal File Operations
All of the following operations are invoked using the ioctl (2) System Call. refer to that man page for a description of the request and argp parameters. in addition to the IOCTL requests defined here, the specific line discipline in effect will define other requests specific to it (actually termios (4) defines them as function CILS, not IOCTL requests .) the following section lists the available IOCTL requests. the name of the request, a description of its purpose, and the typed argp parameter (if any) are listed. for example, the first entry says
And wocould be called on the terminal associated with file descriptor zero by the following code fragment:
Int ldisc;
Ldisc = ttydisc; IOCTL (0, tiocsetd, & ldisc );
Terminal file request descriptions
Tiocsetd int * ldisc
Change to the new line discipline pointed to by ldisc. The available line disciplines are listed in And currently are:
Ttydisc termios interactive line discipline.
Tabldisc tablet line discipline.
Slipdisc serial IP line discipline.
Pppdisc PPP line discipline.
Netgraphdisc
Netgraph ng_tty (4) line discipline.
Tiocgetd int * ldisc
Return the current line discipline in the integer pointed to by ldisc.
Tiocsbrk void
Set the terminal hardware into break condition.
Tioccbrk void
Clear the terminal hardware break condition.
Tiocsdtr void
Assert data terminal ready (DTR ).
Tioccdtr void
Clear Data Terminal ready (DTR ).
Tiocgpgrp int * tpgrp
Return the current process group with which the terminal is associated in the integer pointed to by tpgrp. This is the underlying call that implements the termios (4) tcgetattr call.
Tiocspgrp int * tpgrp
Associate the terminal with the process group (as an integer) pointed to by tpgrp. This is the underlying call that implements the termios (4) tcsetattr call.
Tiocgeta struct termios * Term
Place the current value of the termios State associated with the device in the termios structure pointed to by term. This is the underlying call that implements the termios (4) tcgetattr call.
Tiocseta struct termios * Term
Set the termios State associated with the device immediately. This is the underlying call that implements the termios (4) tcsetattr call with the tcsanow option.
Tiocsetaw struct termios * Term
First wait for any output to complete, then set the termios State associated with the device. This is the underlying call that implements the termios (4) tcsetattr call with the tcsadrain option.
Tiocsetaf struct termios * Term
First 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 termios (4) tcsetattr call with the tcsaflush option.
Tiocoutq int * num
Place the current number of characters in the output queue in the integer pointed to by num.
Tiocsti char * CP
Simulate typed input. pretend as if the terminal specified ed the character pointed to by CP.
Tiocnotty void
This call is obsolete but left for compatibility. in the past, when a process that didn't have a controlling terminal (see the controlling terminal in termios (4) first opened a terminal device, it acquired that terminal as its controlling terminal. for some programs this was a hazard as they didn't want a controlling terminal in the first place, and this provided a mechanic to disassociate the controlling terminal from the calling process. it must be called by opening the file/dev/tty and calling tiocnotty on that file descriptor.
The current system does not allocate a controlling terminal to a process on an open call: there is a specific IOCTL called tiosctty to make a terminal the controlling terminal. in addition, a program can fork and call the setsid System Call which will place the process into its own session-which has the effect of disassociating it from the controlling terminal. this is the new and preferred method for programs to lose their controlling terminal.
Tiocstop void
Stop output on the terminal (like typing ^ s at the keyboard ).
Tiocstart void
Start output on the terminal (like typing ^ Q at the keyboard ).
Tiocsctty void
Make the terminal the controlling terminal for the process (the process must not currently have a controlling terminal ).
Tiocdrain void
Wait until all output is drained.
Tiocexcl void
Set exclusive use on the terminal. no further opens are permitted partition t by root. of course, this means that programs that are run by root (or setuid) will not obey the exclusive setting-which limits the usefulness of this feature.
Tiocnxcl void
Clear exclusive use of the terminal. Further Opens are permitted.
Tiocflush int * What
If the value of the int pointed to by what contains the fread bit as defined in , Then all characters in the input queue are cleared. if it contains the fwrite bit, then all characters in the output queue are cleared. if the value of the integer is zero, then it behaves as if both the fread and fwrite bits were set (I. e. clears both queues ).
Tiocgwinsz struct winsize * WS
Put the window size information associated with the terminal in the winsize structure pointed to by WS. the window size structure contains the number of rows and columns (and pixels if appropriate) of the devices attached to the terminal. it is set by user software and is the means by which most full-screen oriented programs determine the screen size. the winsize structure is defined in .
Tiocswinsz struct winsize * WS
Set the window size associated with the terminal to be the value in the winsize structure pointed to by WS (see above ).
Tioccons int * on
If on points to a non-zero integer, redirect kernel console output (kernel printf's) to this terminal. if on points to a zero integer, redirect kernel console output back to the normal console. this is usually used on workstations to redirect kernel messages to a participant window.
Tiocmset int * State
The integer pointed to by State contains bits that correspond to modem state. Following is a list of Defined variables and the modem State they represent:
Tiocm_le line enable.
Tiocm_dtr
Data Terminal ready.
Tiocm_rts
Request to send.
Tiocm_st secondary transmit.
Tiocm_sr secondary receive.
Tiocm_cts
Clear to send.
Tiocm_car
Carrier detect.
Tiocm_cd carrier detect (Synonym ).
Tiocm_rng
Ring indication.
Tiocm_ri ring indication (Synonym ).
Tiocm_dsr
Data Set ready.
This call sets the terminal modem State to that represented by state. Not all terminals may support this.
Tiocmget int * State
Return the current state of the terminal modem lines as represented above in the integer pointed to by state.
Tiocmbis int * State
The bits in the integer pointed to by state represent modem state as described above, however the state is or-ed in with the current state.
Tiocmbic int * State
The bits in the integer pointed to by state represent modem state as described above, however each bit which is on in state is cleared in the terminal.
See also
Stty (1), IOCTL (2), ng_tty (4), Pty (4), termios (4), Getty (8)
Search for or go to top of page | section 4 | Main Index
August 14,199 2 tty (4)