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