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