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