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