xref: /csrg-svn/share/man/man4/tty.4 (revision 55908)
1.\" Copyright (c) 1991, 1992 The Regents of the University of California.
2.\" All rights reserved.
3.\"
4.\" %sccs.include.redist.roff%
5.\"
6.\"     @(#)tty.4	6.10 (Berkeley) 08/14/92
7.\"
8.Dd
9.Dt TTY 4
10.Os BSD 4
11.Sh NAME
12.Nm tty
13.Nd general terminal interface
14.Sh SYNOPSIS
15.Fd #include <sys/ioctl.h>
16.Sh DESCRIPTION
17This section describes the interface to the terminal drivers
18in the system.
19.Ss Terminal Special Files
20Each hardware terminal port on the system usually has a terminal special device
21file associated with it in the directory ``/dev/'' (for
22example, ``/dev/tty03'').
23When a user logs into
24the system on one of these hardware terminal ports, the system has already
25opened the associated device and prepared the line for normal interactive
26use (see
27.Xr getty 8 .)
28There is also a special case of a terminal file that connects not to
29a hardware terminal port, but to another program on the other side.
30These special terminal devices are called
31.Em ptys
32and provide the mechanism necessary to give users the same interface to the
33system when logging in over a network (using
34.Xr rlogin 1 ,
35or
36.Xr telnet 1
37for example.)  Even in these cases the details of how the terminal
38file was opened and set up is already handled by special software
39in the system.
40Thus, users do not normally need to worry about the details of
41how these lines are opened or used.  Also, these lines are often used
42for dialing out of a system (through an out-calling modem), but again
43the system provides programs that hide the details of accessing
44these terminal special files (see
45.Xr tip 2 .)
46.Pp
47When an interactive user logs in, the system prepares the line to
48behave in a certain way (called a
49.Em "line discipline" ),
50the particular details of which is described in
51.Xr stty 1
52at the command level, and in
53.Xr termios 4
54at the programming level.  A user may be concerned with changing
55settings associated with his particular login terminal and should refer
56to the preceding man pages for the common cases.  The remainder of
57this man page is concerned
58with describing details of using and controlling terminal devices
59at a low level, such as that possibly required by a program wishing
60to provide features similar to those provided by the system.
61.Ss Line disciplines
62A terminal file is used like any other file in the system in that
63it can be opened, read, and written to using standard system
64calls.  For each existing terminal file, a software processing module
65called a
66.Em "line discipline"
67is associated with it.  The
68.Em "line discipline"
69essentially glues the low level device driver code with the high
70level generic interface routines (such as
71.Xr read 2
72and
73.Xr write 2 ),
74and is responsible for implementing the semantics associated
75with the device.  When a terminal file is first opened by a program,
76the default
77.Em "line discipline"
78called the
79.Dv termios
80line discipline is associated with the file.  This is the primary
81line discipline that is used in most cases and provides the semantics
82that users normally associate with a terminal.  When the
83.Dv termios
84line discipline is in effect, the terminal file behaves and is
85operated according to the rules described in
86.Xr termios 4 .
87Please refer to that man page for a full description of the terminal
88semantics.
89The operations described here
90generally represent features common
91across all
92.Em "line disciplines"
93however, some of these calls may not
94make sense in conjunction with a line discipline other than
95.Dv termios ,
96and some may not be supported by the underlying
97hardware or (lack thereof, as in the case of ptys).
98.Ss Terminal File Operations
99All of the following operations are invoked using the
100.Xr ioctl 2
101system call.  Refer to that man page for a description of
102the
103.Em request
104and
105.Em argp
106parameter.
107In addition to the ioctl
108.Em requests
109defined here, the specific line discipline
110in effect will define other
111.Em requests
112specific to it (actually
113.Xr termios 4
114defines them as function calls, not ioctl
115.Em requests .)
116The following section lists the available ioctl requests.  The
117name of the request and the typed
118.Em argp
119parameter (if any)
120is listed along with a description of its
121purpose.  For example, the first entry says
122.sp
123.D1 Em "TIOCSETD	int *ldisc"
124.sp
125and would be called on the terminal associated with
126file discriptor zero by the following code fragment:
127.Bd -literal
128	int ldisc;
129
130	ldisc = TTYDISC;
131	ioctl(0, TIOCSETD, &ldisc);
132.Ed
133.Ss Terminal File Request Descriptions
134.Bl -tag -width XXX
135.It Va Dv TIOCSETD Fa \t\tint *ldisc
136.sp
137Change to the new line discipline pointed to by
138.Fa ldisc .
139The available line disciplines are listed in
140.Pa <sys/termios.h>
141and currently are:
142.Bl -hang -width XXXXXXXXXXX
143.It TTYDISC
144Termios interactive line discipline.
145.It TABLDISC
146Tablet line discipline.
147.It SLIPDISC
148Serial IP line discipline.
149.El
150.It Va Dv TIOCGETD Fa \t\tint *ldisc
151.sp
152Return the current line discipline in the integer pointed to by
153.Fa ldisc .
154.It Va Dv TIOCSBRK Fa \t\tvoid
155.sp
156Set the terminal hardware into BREAK condition.
157.It Va Dv TIOCCBRK Fa \t\tvoid
158.sp
159Clear the terminal hardware BREAK condition.
160.It Va Dv TIOCSDTR Fa \t\tvoid
161.sp
162Assert data terminal ready (DTR).
163.It Va Dv TIOCCDTR Fa \t\tvoid
164.sp
165Clear data terminal ready (DTR).
166.It Va Dv TIOCGPGRP Fa \t\tint *tpgrp
167.sp
168Return the current process group the terminal is associated
169with in the integer pointed to by
170.Fa tpgrp .
171This is the underlying call that implements the
172.Xr termios 4
173.Fn tcgetattr
174call.
175.It Va Dv TIOCSPGRP Fa \t\tint *tpgrp
176Associate the terminal with the process group (as an integer) pointed to by
177.Fa tpgrp .
178This is the underlying call that implements the
179.Xr termios 4
180.Fn tcsetattr
181call.
182.sp
183.It Va Dv TIOCGETA Fa \t\tstruct termios *term
184.sp
185Place the current value of the termios state associated with the
186device in the termios structure pointed to by
187.Fa term .
188This is the underlying call that implements the
189.Xr termios 4
190.Fn tcgetattr
191call.
192.It Va Dv TIOCSETA Fa \t\tstruct termios *term
193.sp
194Set the termios state associated with the device immediatly.
195This is the underlying call that implements the
196.Xr termios 4
197.Fn tcsetattr
198call with the
199.Dv TCSANOW
200option.
201.It Va Dv TIOCSETAW Fa \t\tstruct termios *term
202.sp
203First wait for any output to complete, then set the termios state
204associated with the device.
205This is the underlying call that implements the
206.Xr termios 4
207.Fn tcsetattr
208call with the
209.Dv TCSADRAIN
210option.
211.It Va Dv TIOCSETAF Fa \t\tstruct termios *term
212.sp
213First wait for any output to complete, clear any pending input,
214then set the termios state associated with the device.
215This is the underlying call that implements the
216.Xr termios 4
217.Fn tcsetattr
218call with the
219.Dv TCSAFLUSH
220option.
221.It Va Dv TIOCOUTQ Fa \t\tint *num
222.sp
223Place the current number of characters in the output queue in the
224integer pointed to by
225.Fa num .
226.It Va Dv TIOCSTI Fa \t\tchar *cp
227.sp
228Simulate typed input.  Pretend as if the terminal recieved the
229character pointed to by
230.Fa cp .
231.It Va Dv TIOCNOTTY Fa \t\tvoid
232This call is obsolete but left for compatability.  In the past, when
233a process that didn't have a controlling terminal (see
234.Em The Controlling Terminal
235in
236.Xr termios 4 )
237first opened a terminal device, it acquired that terminal as its
238controlling terminal.  For some programs this was a hazard as they
239didn't want a controlling terminal in the first place, and this
240provided a mechanism to disassociate the controlling terminal from
241the calling process.  It
242.Em must
243be called by opening the file
244.Pa /dev/tty
245and calling
246.Dv TIOCNOTTY
247on that file descriptor.
248.Pp
249The current system does not allocate a controlling terminal to
250a process on an
251.Fn open
252call: there is a specific ioctl called
253.Dv TIOSCTTY
254to make a terminal the controlling
255terminal.
256In addition, a program can
257.Fn fork
258and call the
259.Fn setsid
260system call which will place the process into its own session - which
261has the effect of disassociating it from the controlling terminal.  This
262is the new and prefered method for programs to lose their controlling
263terminal.
264.sp
265.It Va Dv TIOCSTOP Fa \t\tvoid
266.sp
267Stop output on the terminal (like typing ^S at the keyboard).
268.It Va Dv TIOCSTART Fa \t\tvoid
269.sp
270Start output on the terminal (like typing ^Q at the kayboard).
271.It Va Dv TIOCSCTTY Fa \t\tvoid
272Make the terminal the controlling terminal for the process (the process
273must not currently have a controlling terminal).
274.sp
275.It Va Dv TIOCDRAIN Fa \t\tvoid
276.sp
277Wait until all output is drained.
278.It Va Dv TIOCEXCL Fa \t\tvoid
279.sp
280Set exclusive use on the terminal.  No further opens are permitted
281except by root.  Of course, this means that programs that are run by
282root (or setuid) will not obey the exclusive setting - which limits
283the usefullness of this feature.
284.It Va Dv TIOCNXCL Fa \t\tvoid
285.sp
286Clear exclusive use of the terminal.  Further opens are permitted.
287.It Va Dv TIOCFLUSH Fa \t\tint *what
288.sp
289If the value of the int pointed to by
290.Fa what
291contains the
292.Dv FREAD
293bit as defined in
294.Pa <sys/file.h> ,
295then all characters in the input queue are cleared.  If it contains
296the
297.Dv FWRITE
298bit, then all characters in the output queue are cleared.  If the
299value of the integer is zero, then it behaves as if both the FREAD
300and FWRITE bits were set (i.e. clears both queues).
301.It Va Dv TIOCGWINSZ Fa \t\tstruct winsize *ws
302.sp
303Put the window size information associated with the terminal in the
304.Va winsize
305structure pointed to by
306.Fa ws .
307The window size structure contains the number of rows and columns (and pixels
308if appropiate) of the devices attached to the terminal.  It is set by user software
309and is the means by which most full\&-screen oriented programs determine the
310screen size.  The
311.Va winsize
312structure is defined in
313.Pa <sys/ioctl.h> .
314.It Va Dv TIOCSWINSZ Fa \t\tstruct winsize *ws
315.sp
316Set the window size associated with the terminal to be the value in
317the
318.Va winsize
319structure pointed to by
320.Fa ws
321(see above).
322.It Va Dv TIOCCONS Fa \t\tint *on
323.sp
324If
325.Fa on
326points to a non-zero integer, redirect kernel console output (kernel printf's)
327to this terminal.
328If
329.Fa on
330points to a zero integer, redirect kernel console output back to the normal
331console.  This is usually used on workstations to redirect kernel messages
332to a particular window.
333.It Va Dv TIOCMSET Fa \t\tint *state
334.sp
335The integer pointed to by
336.Fa state
337contains bits that correspond to modem state.  Following is a list
338of defined variables and the modem state they represent:
339.Bl -hang -width XXXXXXXXXXX
340.It TIOCM_LE
341Line Enable.
342.It TIOCM_DTR
343Data Terminal Ready.
344.It TIOCM_RTS
345Request To Send.
346.It TIOCM_ST
347Secondary Transmit.
348.It TIOCM_SR
349Secondary Recieve.
350.It TIOCM_CTS
351Clear To Send.
352.It TIOCM_CAR
353Carrier Detect.
354.It TIOCM_CD
355Carier Detect (synonym).
356.It TIOCM_RNG
357Ring Indication.
358.It TIOCM_RI
359Ring Indication (synonym).
360.It TIOCM_DSR
361Data Set Ready.
362.El
363.sp
364This call sets the terminal modem state to that represented by
365.Fa state .
366Not all terminals may support this.
367.It Va Dv TIOCMGET Fa \t\tint *state
368Return the current state of the terminal modem lines as represented
369above in the integer pointed to by
370.Fa state .
371.It Va Dv TIOCMBIS Fa \t\tint *state
372The bits in the integer pointed to by
373.Fa state
374represent modem state as described above, however the state is OR-ed
375in with the current state.
376.It Va Dv TIOCMBIC Fa \t\tint *state
377The bits in the integer pointed to by
378.Fa state
379represent modem state as described above, however each bit which is on
380in
381.Fa state
382is cleared in the terminal.
383.El
384.Sh SEE ALSO
385.Xr getty 8 ,
386.Xr ioctl 2 ,
387.Xr pty 4 ,
388.Xr stty 1 ,
389.Xr termios 4
390