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