]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - share/man/man4/tty.4
This commit was generated by cvs2svn to compensate for changes in r125820,
[FreeBSD/FreeBSD.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 August 14, 1992
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 Line disciplines
92 A terminal file is used like any other file in the system in that
93 it can be opened, read, and written to using standard system
94 calls.
95 For each existing terminal file, there is a software processing module
96 called a
97 .Em "line discipline"
98 is associated with it.  The
99 .Em "line discipline"
100 essentially glues the low level device driver code with the high
101 level generic interface routines (such as
102 .Xr read 2
103 and
104 .Xr write 2 ) ,
105 and is responsible for implementing the semantics associated
106 with the device.
107 When a terminal file is first opened by a program, the default
108 .Em "line discipline"
109 called the
110 .Dv termios
111 line discipline is associated with the file.
112 This is the primary
113 line discipline that is used in most cases and provides the semantics
114 that users normally associate with a terminal.
115 When the
116 .Dv termios
117 line discipline is in effect, the terminal file behaves and is
118 operated according to the rules described in
119 .Xr termios 4 .
120 Please refer to that man page for a full description of the terminal
121 semantics.
122 The operations described here
123 generally represent features common
124 across all
125 .Em "line disciplines" ,
126 however some of these calls may not
127 make sense in conjunction with a line discipline other than
128 .Dv termios ,
129 and some may not be supported by the underlying
130 hardware (or lack thereof, as in the case of ptys).
131 .Ss Terminal File Operations
132 All of the following operations are invoked using the
133 .Xr ioctl 2
134 system call.
135 Refer to that man page for a description of the
136 .Em request
137 and
138 .Em argp
139 parameters.
140 In addition to the ioctl
141 .Em requests
142 defined here, the specific line discipline
143 in effect will define other
144 .Em requests
145 specific to it (actually
146 .Xr termios 4
147 defines them as function calls, not ioctl
148 .Em requests . )
149 The following section lists the available ioctl requests.
150 The name of the request, a description of its purpose, and the typed
151 .Em argp
152 parameter (if any)
153 are listed.  For example, the first entry says
154 .Pp
155 .D1 Em "TIOCSETD int *ldisc"
156 .Pp
157 and would be called on the terminal associated with
158 file descriptor zero by the following code fragment:
159 .Bd -literal
160         int ldisc;
161
162         ldisc = TTYDISC;
163         ioctl(0, TIOCSETD, &ldisc);
164 .Ed
165 .Ss Terminal File Request Descriptions
166 .Bl -tag -width TIOCGWINSZ
167 .It Dv TIOCSETD Fa int *ldisc
168 Change to the new line discipline pointed to by
169 .Fa ldisc .
170 The available line disciplines are listed in
171 .In sys/ttycom.h
172 and currently are:
173 .Pp
174 .Bl -tag -width NETGRAPHDISC -compact
175 .It TTYDISC
176 Termios interactive line discipline.
177 .It TABLDISC
178 Tablet line discipline.
179 .It SLIPDISC
180 Serial IP line discipline.
181 .It PPPDISC
182 PPP line discipline.
183 .It NETGRAPHDISC
184 Netgraph
185 .Xr ng_tty 4
186 line discipline.
187 .El
188 .Pp
189 .It Dv TIOCGETD Fa int *ldisc
190 Return the current line discipline in the integer pointed to by
191 .Fa ldisc .
192 .It Dv TIOCSBRK Fa void
193 Set the terminal hardware into BREAK condition.
194 .It Dv TIOCCBRK Fa void
195 Clear the terminal hardware BREAK condition.
196 .It Dv TIOCSDTR Fa void
197 Assert data terminal ready (DTR).
198 .It Dv TIOCCDTR Fa void
199 Clear data terminal ready (DTR).
200 .It Dv TIOCGPGRP Fa int *tpgrp
201 Return the current process group with which the terminal is associated
202 in the integer pointed to by
203 .Fa tpgrp .
204 This is the underlying call that implements the
205 .Xr termios 4
206 .Fn tcgetattr
207 call.
208 .It Dv TIOCSPGRP Fa int *tpgrp
209 Associate the terminal with the process group (as an integer) pointed to by
210 .Fa tpgrp .
211 This is the underlying call that implements the
212 .Xr termios 4
213 .Fn tcsetattr
214 call.
215 .It Dv TIOCGETA Fa struct termios *term
216 Place the current value of the termios state associated with the
217 device in the termios structure pointed to by
218 .Fa term .
219 This is the underlying call that implements the
220 .Xr termios 4
221 .Fn tcgetattr
222 call.
223 .It Dv TIOCSETA Fa struct termios *term
224 Set the termios state associated with the device immediately.
225 This is the underlying call that implements the
226 .Xr termios 4
227 .Fn tcsetattr
228 call with the
229 .Dv TCSANOW
230 option.
231 .It Dv TIOCSETAW Fa struct termios *term
232 First wait for any output to complete, then set the termios state
233 associated with the device.
234 This is the underlying call that implements the
235 .Xr termios 4
236 .Fn tcsetattr
237 call with the
238 .Dv TCSADRAIN
239 option.
240 .It Dv TIOCSETAF Fa struct termios *term
241 First wait for any output to complete, clear any pending input,
242 then set the termios state associated with the device.
243 This is the underlying call that implements the
244 .Xr termios 4
245 .Fn tcsetattr
246 call with the
247 .Dv TCSAFLUSH
248 option.
249 .It Dv TIOCOUTQ Fa int *num
250 Place the current number of characters in the output queue in the
251 integer pointed to by
252 .Fa num .
253 .It Dv TIOCSTI Fa char *cp
254 Simulate typed input.
255 Pretend as if the terminal received the character pointed to by
256 .Fa cp .
257 .It Dv TIOCNOTTY Fa void
258 This call is obsolete but left for compatibility.
259 In the past, when a process that didn't have a controlling terminal (see
260 .Em The Controlling Terminal
261 in
262 .Xr termios 4 )
263 first opened a terminal device, it acquired that terminal as its
264 controlling terminal.
265 For some programs this was a hazard as they
266 didn't want a controlling terminal in the first place, and this
267 provided a mechanism to disassociate the controlling terminal from
268 the calling process.
269 It
270 .Em must
271 be called by opening the file
272 .Pa /dev/tty
273 and calling
274 .Dv TIOCNOTTY
275 on that file descriptor.
276 .Pp
277 The current system does not allocate a controlling terminal to
278 a process on an
279 .Fn open
280 call: there is a specific ioctl called
281 .Dv TIOSCTTY
282 to make a terminal the controlling
283 terminal.
284 In addition, a program can
285 .Fn fork
286 and call the
287 .Fn setsid
288 system call which will place the process into its own session - which
289 has the effect of disassociating it from the controlling terminal.
290 This is the new and preferred method for programs to lose their controlling
291 terminal.
292 .It Dv TIOCSTOP Fa void
293 Stop output on the terminal (like typing ^S at the keyboard).
294 .It Dv TIOCSTART Fa void
295 Start output on the terminal (like typing ^Q at the keyboard).
296 .It Dv TIOCSCTTY Fa void
297 Make the terminal the controlling terminal for the process (the process
298 must not currently have a controlling terminal).
299 .It Dv TIOCDRAIN Fa void
300 Wait until all output is drained.
301 .It Dv TIOCEXCL Fa void
302 Set exclusive use on the terminal.
303 No further opens are permitted except by root.
304 Of course, this means that programs that are run by
305 root (or setuid) will not obey the exclusive setting - which limits
306 the usefulness of this feature.
307 .It Dv TIOCNXCL Fa void
308 Clear exclusive use of the terminal.
309 Further opens are permitted.
310 .It Dv TIOCFLUSH Fa int *what
311 If the value of the int pointed to by
312 .Fa what
313 contains the
314 .Dv FREAD
315 bit as defined in
316 .In sys/file.h ,
317 then all characters in the input queue are cleared.
318 If it contains the
319 .Dv FWRITE
320 bit, then all characters in the output queue are cleared.
321 If the value of the integer is zero, then it behaves as if both the
322 .Dv FREAD
323 and
324 .Dv FWRITE
325 bits were set (i.e. clears both queues).
326 .It Dv TIOCGWINSZ Fa struct winsize *ws
327 Put the window size information associated with the terminal in the
328 .Va winsize
329 structure pointed to by
330 .Fa ws .
331 The window size structure contains the number of rows and columns (and pixels
332 if appropriate) of the devices attached to the terminal.
333 It is set by user software
334 and is the means by which most full\&-screen oriented programs determine the
335 screen size.
336 The
337 .Va winsize
338 structure is defined in
339 .In sys/ioctl.h .
340 .It Dv TIOCSWINSZ Fa struct winsize *ws
341 Set the window size associated with the terminal to be the value in
342 the
343 .Va winsize
344 structure pointed to by
345 .Fa ws
346 (see above).
347 .It Dv TIOCCONS Fa int *on
348 If
349 .Fa on
350 points to a non-zero integer, redirect kernel console output (kernel printf's)
351 to this terminal.
352 If
353 .Fa on
354 points to a zero integer, redirect kernel console output back to the normal
355 console.
356 This is usually used on workstations to redirect kernel messages
357 to a particular window.
358 .It Dv TIOCMSET Fa int *state
359 The integer pointed to by
360 .Fa state
361 contains bits that correspond to modem state.
362 Following is a list of defined variables and the modem state they represent:
363 .Pp
364 .Bl -tag -width TIOCMXCTS -compact
365 .It TIOCM_LE
366 Line Enable.
367 .It TIOCM_DTR
368 Data Terminal Ready.
369 .It TIOCM_RTS
370 Request To Send.
371 .It TIOCM_ST
372 Secondary Transmit.
373 .It TIOCM_SR
374 Secondary Receive.
375 .It TIOCM_CTS
376 Clear To Send.
377 .It TIOCM_CAR
378 Carrier Detect.
379 .It TIOCM_CD
380 Carrier Detect (synonym).
381 .It TIOCM_RNG
382 Ring Indication.
383 .It TIOCM_RI
384 Ring Indication (synonym).
385 .It TIOCM_DSR
386 Data Set Ready.
387 .El
388 .Pp
389 This call sets the terminal modem state to that represented by
390 .Fa state .
391 Not all terminals may support this.
392 .It Dv TIOCMGET Fa int *state
393 Return the current state of the terminal modem lines as represented
394 above in the integer pointed to by
395 .Fa state .
396 .It Dv TIOCMBIS Fa int *state
397 The bits in the integer pointed to by
398 .Fa state
399 represent modem state as described above, however the state is OR-ed
400 in with the current state.
401 .It Dv TIOCMBIC Fa int *state
402 The bits in the integer pointed to by
403 .Fa state
404 represent modem state as described above, however each bit which is on
405 in
406 .Fa state
407 is cleared in the terminal.
408 .El
409 .Sh IMPLEMENTATION NOTES
410 The total number of input and output bytes
411 through all terminal devices
412 are available via the
413 .Va kern.tk_nin
414 and
415 .Va kern.tk_nout
416 read-only
417 .Xr sysctl 8
418 variables.
419 .Sh SEE ALSO
420 .Xr stty 1 ,
421 .Xr ioctl 2 ,
422 .Xr ng_tty 4 ,
423 .Xr pty 4 ,
424 .Xr termios 4 ,
425 .Xr getty 8