1.\" Copyright (c) 1991, 1992, 1993 2.\" The Regents of the University of California. All rights reserved. 3.\" 4.\" Redistribution and use in source and binary forms, with or without 5.\" modification, are permitted provided that the following conditions 6.\" are met: 7.\" 1. Redistributions of source code must retain the above copyright 8.\" notice, this list of conditions and the following disclaimer. 9.\" 2. Redistributions in binary form must reproduce the above copyright 10.\" notice, this list of conditions and the following disclaimer in the 11.\" documentation and/or other materials provided with the distribution. 12.\" 3. Neither the name of the University nor the names of its contributors 13.\" may be used to endorse or promote products derived from this software 14.\" without specific prior written permission. 15.\" 16.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 17.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 20.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26.\" SUCH DAMAGE. 27.\" 28.\" @(#)tty.4 8.3 (Berkeley) 4/19/94 29.\" $FreeBSD$ 30.\" 31.Dd December 26, 2009 32.Dt TTY 4 33.Os 34.Sh NAME 35.Nm tty 36.Nd general terminal interface 37.Sh SYNOPSIS 38.In sys/ioctl.h 39.Sh DESCRIPTION 40This section describes the interface to the terminal drivers 41in the system. 42.Ss Terminal Special Files 43Each hardware terminal port on the system usually has a terminal special device 44file associated with it in the directory ``/dev/'' (for 45example, ``/dev/tty03''). 46When a user logs into 47the system on one of these hardware terminal ports, the system has already 48opened the associated device and prepared the line for normal interactive 49use (see 50.Xr getty 8 . ) 51There is also a special case of a terminal file that connects not to 52a hardware terminal port, but to another program on the other side. 53These special terminal devices are called 54.Em ptys 55and provide the mechanism necessary to give users the same interface to the 56system when logging in over a network (using 57.Xr rlogin 1 , 58or 59.Xr telnet 1 60for example). 61Even in these cases the details of how the terminal 62file was opened and set up is already handled by special software 63in the system. 64Thus, users do not normally need to worry about the details of 65how these lines are opened or used. 66Also, these lines are often used 67for dialing out of a system (through an out-calling modem), but again 68the system provides programs that hide the details of accessing 69these terminal special files (see 70.Xr tip 1 ) . 71.Pp 72When an interactive user logs in, the system prepares the line to 73behave in a certain way (called a 74.Em "line discipline" ) , 75the particular details of which is described in 76.Xr stty 1 77at the command level, and in 78.Xr termios 4 79at the programming level. 80A user may be concerned with changing 81settings associated with his particular login terminal and should refer 82to the preceding man pages for the common cases. 83The remainder of this man page is concerned 84with describing details of using and controlling terminal devices 85at a low level, such as that possibly required by a program wishing 86to provide features similar to those provided by the system. 87.Ss Terminal File Operations 88All of the following operations are invoked using the 89.Xr ioctl 2 90system call. 91Refer to that man page for a description of the 92.Em request 93and 94.Em argp 95parameters. 96In addition to the ioctl 97.Em requests 98defined here, the specific line discipline 99in effect will define other 100.Em requests 101specific to it (actually 102.Xr termios 4 103defines them as function calls, not ioctl 104.Em requests . ) 105The following section lists the available ioctl requests. 106The name of the request, a description of its purpose, and the typed 107.Em argp 108parameter (if any) 109are listed. 110For example, the first entry says 111.Pp 112.D1 Em "TIOCSPGRP int *tpgrp" 113.Pp 114and would be called on the terminal associated with 115file descriptor zero by the following code fragment: 116.Bd -literal 117 int pgrp; 118 119 pgrp = getpgrp(); 120 ioctl(0, TIOCSPGRP, &pgrp); 121.Ed 122.Ss Terminal File Request Descriptions 123.Bl -tag -width TIOCGWINSZ 124.It Dv TIOCSETD Fa int *ldisc 125This call is obsolete but left for compatibility. 126Before 127.Fx 8.0 , 128it would change to the new line discipline pointed to by 129.Fa ldisc . 130.Pp 131.It Dv TIOCGETD Fa int *ldisc 132Return the current line discipline in the integer pointed to by 133.Fa ldisc . 134.It Dv TIOCSBRK Fa void 135Set the terminal hardware into BREAK condition. 136.It Dv TIOCCBRK Fa void 137Clear the terminal hardware BREAK condition. 138.It Dv TIOCSDTR Fa void 139Assert data terminal ready (DTR). 140.It Dv TIOCCDTR Fa void 141Clear data terminal ready (DTR). 142.It Dv TIOCGPGRP Fa int *tpgrp 143Return the current process group with which the terminal is associated 144in the integer pointed to by 145.Fa tpgrp . 146This is the underlying call that implements the 147.Xr termios 4 148.Fn tcgetattr 149call. 150.It Dv TIOCSPGRP Fa int *tpgrp 151Associate the terminal with the process group (as an integer) pointed to by 152.Fa tpgrp . 153This is the underlying call that implements the 154.Xr termios 4 155.Fn tcsetattr 156call. 157.It Dv TIOCGETA Fa struct termios *term 158Place the current value of the termios state associated with the 159device in the termios structure pointed to by 160.Fa term . 161This is the underlying call that implements the 162.Xr termios 4 163.Fn tcgetattr 164call. 165.It Dv TIOCSETA Fa struct termios *term 166Set the termios state associated with the device immediately. 167This is the underlying call that implements the 168.Xr termios 4 169.Fn tcsetattr 170call with the 171.Dv TCSANOW 172option. 173.It Dv TIOCSETAW Fa struct termios *term 174First wait for any output to complete, then set the termios state 175associated with the device. 176This is the underlying call that implements the 177.Xr termios 4 178.Fn tcsetattr 179call with the 180.Dv TCSADRAIN 181option. 182.It Dv TIOCSETAF Fa struct termios *term 183First wait for any output to complete, clear any pending input, 184then set the termios state associated with the device. 185This is the underlying call that implements the 186.Xr termios 4 187.Fn tcsetattr 188call with the 189.Dv TCSAFLUSH 190option. 191.It Dv TIOCOUTQ Fa int *num 192Place the current number of characters in the output queue in the 193integer pointed to by 194.Fa num . 195.It Dv TIOCSTI Fa char *cp 196Simulate typed input. 197Pretend as if the terminal received the character pointed to by 198.Fa cp . 199.It Dv TIOCNOTTY Fa void 200This call is obsolete but left for compatibility. 201In the past, when a process that did not have a controlling terminal (see 202.Em The Controlling Terminal 203in 204.Xr termios 4 ) 205first opened a terminal device, it acquired that terminal as its 206controlling terminal. 207For some programs this was a hazard as they 208did not want a controlling terminal in the first place, and this 209provided a mechanism to disassociate the controlling terminal from 210the calling process. 211It 212.Em must 213be called by opening the file 214.Pa /dev/tty 215and calling 216.Dv TIOCNOTTY 217on that file descriptor. 218.Pp 219The current system does not allocate a controlling terminal to 220a process on an 221.Fn open 222call: there is a specific ioctl called 223.Dv TIOCSCTTY 224to make a terminal the controlling 225terminal. 226In addition, a program can 227.Fn fork 228and call the 229.Fn setsid 230system call which will place the process into its own session - which 231has the effect of disassociating it from the controlling terminal. 232This is the new and preferred method for programs to lose their controlling 233terminal. 234.It Dv TIOCSTOP Fa void 235Stop output on the terminal (like typing ^S at the keyboard). 236.It Dv TIOCSTART Fa void 237Start output on the terminal (like typing ^Q at the keyboard). 238.It Dv TIOCSCTTY Fa void 239Make the terminal the controlling terminal for the process (the process 240must not currently have a controlling terminal). 241.It Dv TIOCDRAIN Fa void 242Wait until all output is drained. 243.It Dv TIOCEXCL Fa void 244Set exclusive use on the terminal. 245No further opens are permitted except by root. 246Of course, this means that programs that are run by 247root (or setuid) will not obey the exclusive setting - which limits 248the usefulness of this feature. 249.It Dv TIOCNXCL Fa void 250Clear exclusive use of the terminal. 251Further opens are permitted. 252.It Dv TIOCFLUSH Fa int *what 253If the value of the int pointed to by 254.Fa what 255contains the 256.Dv FREAD 257bit as defined in 258.In sys/file.h , 259then all characters in the input queue are cleared. 260If it contains the 261.Dv FWRITE 262bit, then all characters in the output queue are cleared. 263If the value of the integer is zero, then it behaves as if both the 264.Dv FREAD 265and 266.Dv FWRITE 267bits were set (i.e., clears both queues). 268.It Dv TIOCGWINSZ Fa struct winsize *ws 269Put the window size information associated with the terminal in the 270.Va winsize 271structure pointed to by 272.Fa ws . 273The window size structure contains the number of rows and columns (and pixels 274if appropriate) of the devices attached to the terminal. 275It is set by user software 276and is the means by which most full\&-screen oriented programs determine the 277screen size. 278The 279.Va winsize 280structure is defined in 281.In sys/ioctl.h . 282.It Dv TIOCSWINSZ Fa struct winsize *ws 283Set the window size associated with the terminal to be the value in 284the 285.Va winsize 286structure pointed to by 287.Fa ws 288(see above). 289.It Dv TIOCCONS Fa int *on 290If 291.Fa on 292points to a non-zero integer, redirect kernel console output (kernel printf's) 293to this terminal. 294If 295.Fa on 296points to a zero integer, redirect kernel console output back to the normal 297console. 298This is usually used on workstations to redirect kernel messages 299to a particular window. 300.It Dv TIOCMSET Fa int *state 301The integer pointed to by 302.Fa state 303contains bits that correspond to modem state. 304Following is a list of defined variables and the modem state they represent: 305.Pp 306.Bl -tag -width TIOCMXCTS -compact 307.It TIOCM_LE 308Line Enable. 309.It TIOCM_DTR 310Data Terminal Ready. 311.It TIOCM_RTS 312Request To Send. 313.It TIOCM_ST 314Secondary Transmit. 315.It TIOCM_SR 316Secondary Receive. 317.It TIOCM_CTS 318Clear To Send. 319.It TIOCM_CAR 320Carrier Detect. 321.It TIOCM_CD 322Carrier Detect (synonym). 323.It TIOCM_RNG 324Ring Indication. 325.It TIOCM_RI 326Ring Indication (synonym). 327.It TIOCM_DSR 328Data Set Ready. 329.El 330.Pp 331This call sets the terminal modem state to that represented by 332.Fa state . 333Not all terminals may support this. 334.It Dv TIOCMGET Fa int *state 335Return the current state of the terminal modem lines as represented 336above in the integer pointed to by 337.Fa state . 338.It Dv TIOCMBIS Fa int *state 339The bits in the integer pointed to by 340.Fa state 341represent modem state as described above, however the state is OR-ed 342in with the current state. 343.It Dv TIOCMBIC Fa int *state 344The bits in the integer pointed to by 345.Fa state 346represent modem state as described above, however each bit which is on 347in 348.Fa state 349is cleared in the terminal. 350.El 351.Sh IMPLEMENTATION NOTES 352The total number of input and output bytes 353through all terminal devices 354are available via the 355.Va kern.tk_nin 356and 357.Va kern.tk_nout 358read-only 359.Xr sysctl 8 360variables. 361.Sh SEE ALSO 362.Xr stty 1 , 363.Xr ioctl 2 , 364.Xr ng_tty 4 , 365.Xr pty 4 , 366.Xr termios 4 , 367.Xr getty 8 368