summaryrefslogtreecommitdiff
path: root/static/freebsd/man4/tty.4 3.html
blob: 0145d281788f0a9844d097fa79e52b8bb89a568f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
<table class="head">
  <tr>
    <td class="head-ltitle">TTY(4)</td>
    <td class="head-vol">Device Drivers Manual</td>
    <td class="head-rtitle">TTY(4)</td>
  </tr>
</table>
<div class="manual-text">
<section class="Sh">
<h1 class="Sh" id="NAME"><a class="permalink" href="#NAME">NAME</a></h1>
<p class="Pp"><code class="Nm">tty</code> &#x2014; <span class="Nd">general
    terminal interface</span></p>
</section>
<section class="Sh">
<h1 class="Sh" id="SYNOPSIS"><a class="permalink" href="#SYNOPSIS">SYNOPSIS</a></h1>
<p class="Pp"><code class="In">#include
    &lt;<a class="In">sys/ioctl.h</a>&gt;</code></p>
</section>
<section class="Sh">
<h1 class="Sh" id="DESCRIPTION"><a class="permalink" href="#DESCRIPTION">DESCRIPTION</a></h1>
<p class="Pp">This section describes the interface to the terminal drivers in
    the system.</p>
<section class="Ss">
<h2 class="Ss" id="Terminal_Special_Files"><a class="permalink" href="#Terminal_Special_Files">Terminal
  Special Files</a></h2>
<p class="Pp">Each hardware terminal port on the system has several terminal
    special device files associated with it in the directory ``/dev/'' (for
    example, ``/dev/tty03'' and ``/dev/cua03''). When a user logs into the
    system on one of these hardware terminal ports, the system has already
    opened the associated device and prepared the line for normal interactive
    use (see <a class="Xr">getty(8)</a>.) There is also a special case of a
    terminal file that connects not to a hardware terminal port, but to another
    program on the other side. These special terminal devices are called
    <a class="permalink" href="#ptys"><i class="Em" id="ptys">ptys</i></a> and
    provide the mechanism necessary to give users the same interface to the
    system when logging in over a network (using <a class="Xr">telnet(1)</a> for
    example). Even in these cases the details of how the terminal file was
    opened and set up is already handled by special software in the system.
    Thus, users do not normally need to worry about the details of how these
    lines are opened or used. Also, these lines are often used for dialing out
    of a system (through an out-calling modem), but again the system provides
    programs that hide the details of accessing these terminal special files
    (see <a class="Xr">tip(1)</a>).</p>
<p class="Pp" id="line">When an interactive user logs in, the system prepares
    the line to behave in a certain way (called a
    <a class="permalink" href="#line"><i class="Em">line discipline</i></a>),
    the particular details of which is described in <a class="Xr">stty(1)</a> at
    the command level, and in <a class="Xr">termios(4)</a> at the programming
    level. A user may be concerned with changing settings associated with his
    particular login terminal and should refer to the preceding man pages for
    the common cases. The remainder of this man page is concerned with
    describing details of using and controlling terminal devices at a low level,
    such as that possibly required by a program wishing to provide features
    similar to those provided by the system.</p>
</section>
<section class="Ss">
<h2 class="Ss" id="Terminal_File_Operations"><a class="permalink" href="#Terminal_File_Operations">Terminal
  File Operations</a></h2>
<p class="Pp">All of the following operations are invoked using the
    <a class="Xr">ioctl(2)</a> system call. Refer to that man page for a
    description of the
    <a class="permalink" href="#request"><i class="Em" id="request">request</i></a>
    and <i class="Em">argp</i> parameters. In addition to the ioctl
    <i class="Em">requests</i> defined here, the specific line discipline in
    effect will define other <i class="Em">requests</i> specific to it (actually
    <a class="Xr">termios(4)</a> defines them as function calls, not ioctl
    <i class="Em">requests</i>.) The following section lists the available ioctl
    requests. The name of the request, a description of its purpose, and the
    typed <i class="Em">argp</i> parameter (if any) are listed. For example, the
    first entry says</p>
<p class="Pp"></p>
<div class="Bd Bd-indent"><i class="Em">TIOCSPGRP int *tpgrp</i></div>
<p class="Pp">and would be called on the terminal associated with file
    descriptor zero by the following code fragment:</p>
<div class="Bd Pp Li">
<pre>	int pgrp;

	pgrp = getpgrp();
	ioctl(0, TIOCSPGRP, &amp;pgrp);</pre>
</div>
</section>
<section class="Ss">
<h2 class="Ss" id="Terminal_File_Request_Descriptions"><a class="permalink" href="#Terminal_File_Request_Descriptions">Terminal
  File Request Descriptions</a></h2>
<dl class="Bl-tag">
  <dt id="TIOCSETD"><a class="permalink" href="#TIOCSETD"><code class="Dv">TIOCSETD</code></a>
    <var class="Fa">int *ldisc</var></dt>
  <dd>This call is obsolete but left for compatibility. Before
      <span class="Ux">FreeBSD 8.0</span>, it would change to the new line
      discipline pointed to by <var class="Fa">ldisc</var>.</dd>
  <dt id="TIOCGETD"><a class="permalink" href="#TIOCGETD"><code class="Dv">TIOCGETD</code></a>
    <var class="Fa">int *ldisc</var></dt>
  <dd>Return the current line discipline in the integer pointed to by
      <var class="Fa">ldisc</var>.</dd>
  <dt id="TIOCSBRK"><a class="permalink" href="#TIOCSBRK"><code class="Dv">TIOCSBRK</code></a>
    <var class="Fa">void</var></dt>
  <dd>Set the terminal hardware into BREAK condition.</dd>
  <dt id="TIOCCBRK"><a class="permalink" href="#TIOCCBRK"><code class="Dv">TIOCCBRK</code></a>
    <var class="Fa">void</var></dt>
  <dd>Clear the terminal hardware BREAK condition.</dd>
  <dt id="TIOCSDTR"><a class="permalink" href="#TIOCSDTR"><code class="Dv">TIOCSDTR</code></a>
    <var class="Fa">void</var></dt>
  <dd>Assert data terminal ready (DTR).</dd>
  <dt id="TIOCCDTR"><a class="permalink" href="#TIOCCDTR"><code class="Dv">TIOCCDTR</code></a>
    <var class="Fa">void</var></dt>
  <dd>Clear data terminal ready (DTR).</dd>
  <dt id="TIOCGPGRP"><a class="permalink" href="#TIOCGPGRP"><code class="Dv">TIOCGPGRP</code></a>
    <var class="Fa">int *tpgrp</var></dt>
  <dd>Return the current process group with which the terminal is associated in
      the integer pointed to by <var class="Fa">tpgrp</var>. This is the
      underlying call that implements the <a class="Xr">termios(4)</a>
      <a class="permalink" href="#tcgetattr"><code class="Fn" id="tcgetattr">tcgetattr</code></a>()
      call.</dd>
  <dt id="TIOCSPGRP"><a class="permalink" href="#TIOCSPGRP"><code class="Dv">TIOCSPGRP</code></a>
    <var class="Fa">int *tpgrp</var></dt>
  <dd>Associate the terminal with the process group (as an integer) pointed to
      by <var class="Fa">tpgrp</var>. This is the underlying call that
      implements the <a class="Xr">termios(4)</a>
      <a class="permalink" href="#tcsetattr"><code class="Fn" id="tcsetattr">tcsetattr</code></a>()
      call.</dd>
  <dt id="TIOCGETA"><a class="permalink" href="#TIOCGETA"><code class="Dv">TIOCGETA</code></a>
    <var class="Fa">struct termios *term</var></dt>
  <dd>Place the current value of the termios state associated with the device in
      the termios structure pointed to by <var class="Fa">term</var>. This is
      the underlying call that implements the <a class="Xr">termios(4)</a>
      <code class="Fn">tcgetattr</code>() call.</dd>
  <dt id="TIOCSETA"><a class="permalink" href="#TIOCSETA"><code class="Dv">TIOCSETA</code></a>
    <var class="Fa">struct termios *term</var></dt>
  <dd>Set the termios state associated with the device immediately. This is the
      underlying call that implements the <a class="Xr">termios(4)</a>
      <code class="Fn">tcsetattr</code>() call with the
      <code class="Dv">TCSANOW</code> option.</dd>
  <dt id="TIOCSETAW"><a class="permalink" href="#TIOCSETAW"><code class="Dv">TIOCSETAW</code></a>
    <var class="Fa">struct termios *term</var></dt>
  <dd>First wait for any output to complete, then set the termios state
      associated with the device. This is the underlying call that implements
      the <a class="Xr">termios(4)</a> <code class="Fn">tcsetattr</code>() call
      with the <code class="Dv">TCSADRAIN</code> option.</dd>
  <dt id="TIOCSETAF"><a class="permalink" href="#TIOCSETAF"><code class="Dv">TIOCSETAF</code></a>
    <var class="Fa">struct termios *term</var></dt>
  <dd>First wait for any output to complete, clear any pending input, then set
      the termios state associated with the device. This is the underlying call
      that implements the <a class="Xr">termios(4)</a>
      <code class="Fn">tcsetattr</code>() call with the
      <code class="Dv">TCSAFLUSH</code> option.</dd>
  <dt id="TIOCOUTQ"><a class="permalink" href="#TIOCOUTQ"><code class="Dv">TIOCOUTQ</code></a>
    <var class="Fa">int *num</var></dt>
  <dd>Place the current number of characters in the output queue in the integer
      pointed to by <var class="Fa">num</var>.</dd>
  <dt id="TIOCSTI"><a class="permalink" href="#TIOCSTI"><code class="Dv">TIOCSTI</code></a>
    <var class="Fa">char *cp</var></dt>
  <dd>Simulate typed input. Pretend as if the terminal received the character
      pointed to by <var class="Fa">cp</var>.</dd>
  <dt id="TIOCNOTTY"><a class="permalink" href="#TIOCNOTTY"><code class="Dv">TIOCNOTTY</code></a>
    <var class="Fa">void</var></dt>
  <dd>In the past, when a process that did not have a controlling terminal (see
      <a class="permalink" href="#The"><i class="Em" id="The">The Controlling
      Terminal</i></a> in <a class="Xr">termios(4)</a>) first opened a terminal
      device, it acquired that terminal as its controlling terminal. For some
      programs this was a hazard as they did not want a controlling terminal in
      the first place, and this provides a mechanism to disassociate the
      controlling terminal from the calling process. It
      <a class="permalink" href="#must"><i class="Em" id="must">must</i></a> be
      called by opening the file <span class="Pa">/dev/tty</span> and calling
      <code class="Dv">TIOCNOTTY</code> on that file descriptor.
    <p class="Pp" id="open">The current system does not allocate a controlling
        terminal to a process on an
        <a class="permalink" href="#open"><code class="Fn">open</code></a>()
        call: there is a specific ioctl called <code class="Dv">TIOCSCTTY</code>
        to make a terminal the controlling terminal. In addition, a program can
        <code class="Fn">fork</code>() and call the
        <code class="Fn">setsid</code>() system call which will place the
        process into its own session - which has the effect of disassociating it
        from the controlling terminal. This is the new and preferred method for
        programs to lose their controlling terminal.</p>
    <p class="Pp" id="fork">However, environmental restrictions may prohibit the
        process from being able to
        <a class="permalink" href="#fork"><code class="Fn">fork</code></a>() and
        call the
        <a class="permalink" href="#setsid"><code class="Fn" id="setsid">setsid</code></a>()
        system call to disassociate it from the controlling terminal. In this
        case, it must use <code class="Dv">TIOCNOTTY</code>.</p>
  </dd>
  <dt id="TIOCSTOP"><a class="permalink" href="#TIOCSTOP"><code class="Dv">TIOCSTOP</code></a>
    <var class="Fa">void</var></dt>
  <dd>Stop output on the terminal (like typing ^S at the keyboard).</dd>
  <dt id="TIOCSTART"><a class="permalink" href="#TIOCSTART"><code class="Dv">TIOCSTART</code></a>
    <var class="Fa">void</var></dt>
  <dd>Start output on the terminal (like typing ^Q at the keyboard).</dd>
  <dt id="TIOCSCTTY"><a class="permalink" href="#TIOCSCTTY"><code class="Dv">TIOCSCTTY</code></a>
    <var class="Fa">void</var></dt>
  <dd>Make the terminal the controlling terminal for the process (the process
      must not currently have a controlling terminal).</dd>
  <dt id="TIOCDRAIN"><a class="permalink" href="#TIOCDRAIN"><code class="Dv">TIOCDRAIN</code></a>
    <var class="Fa">void</var></dt>
  <dd>Wait until all output is drained, or until the drain wait timeout
    expires.</dd>
  <dt id="TIOCGDRAINWAIT"><a class="permalink" href="#TIOCGDRAINWAIT"><code class="Dv">TIOCGDRAINWAIT</code></a>
    <var class="Fa">int *timeout</var></dt>
  <dd>Return the current drain wait timeout in seconds.</dd>
  <dt id="TIOCSDRAINWAIT"><a class="permalink" href="#TIOCSDRAINWAIT"><code class="Dv">TIOCSDRAINWAIT</code></a>
    <var class="Fa">int *timeout</var></dt>
  <dd>Set the drain wait timeout in seconds. A value of zero disables timeouts.
      The default drain wait timeout is controlled by the tunable
      <a class="Xr">sysctl(8)</a> OID
    <var class="Va">kern.tty_drainwait</var>.</dd>
  <dt id="TIOCEXCL"><a class="permalink" href="#TIOCEXCL"><code class="Dv">TIOCEXCL</code></a>
    <var class="Fa">void</var></dt>
  <dd>Set exclusive use on the terminal. No further opens are permitted except
      by root. Of course, this means that programs that are run by root (or
      setuid) will not obey the exclusive setting - which limits the usefulness
      of this feature.</dd>
  <dt id="TIOCNXCL"><a class="permalink" href="#TIOCNXCL"><code class="Dv">TIOCNXCL</code></a>
    <var class="Fa">void</var></dt>
  <dd>Clear exclusive use of the terminal. Further opens are permitted.</dd>
  <dt id="TIOCFLUSH"><a class="permalink" href="#TIOCFLUSH"><code class="Dv">TIOCFLUSH</code></a>
    <var class="Fa">int *what</var></dt>
  <dd>If the value of the int pointed to by <var class="Fa">what</var> contains
      the <code class="Dv">FREAD</code> bit as defined in
      <code class="In">&lt;<a class="In">sys/file.h</a>&gt;</code>, then all
      characters in the input queue are cleared. If it contains the
      <code class="Dv">FWRITE</code> bit, then all characters in the output
      queue are cleared. If the value of the integer is zero, then it behaves as
      if both the <code class="Dv">FREAD</code> and
      <code class="Dv">FWRITE</code> bits were set (i.e., clears both
    queues).</dd>
  <dt id="TIOCGWINSZ"><a class="permalink" href="#TIOCGWINSZ"><code class="Dv">TIOCGWINSZ</code></a>
    <var class="Fa">struct winsize *ws</var></dt>
  <dd>Put the window size information associated with the terminal in the
      <var class="Va">winsize</var> structure pointed to by
      <var class="Fa">ws</var>. The window size structure contains the number of
      rows and columns (and pixels if appropriate) of the devices attached to
      the terminal. It is set by user software and is the means by which most
      full-screen oriented programs determine the screen size. The
      <var class="Va">winsize</var> structure is provided by
      <code class="In">&lt;<a class="In">sys/ioctl.h</a>&gt;</code>.</dd>
  <dt id="TIOCSWINSZ"><a class="permalink" href="#TIOCSWINSZ"><code class="Dv">TIOCSWINSZ</code></a>
    <var class="Fa">struct winsize *ws</var></dt>
  <dd>Set the window size associated with the terminal to be the value in the
      <var class="Va">winsize</var> structure pointed to by
      <var class="Fa">ws</var> (see above).</dd>
  <dt id="TIOCCONS"><a class="permalink" href="#TIOCCONS"><code class="Dv">TIOCCONS</code></a>
    <var class="Fa">int *on</var></dt>
  <dd>If <var class="Fa">on</var> points to a non-zero integer, redirect kernel
      console output (kernel printf's) to this terminal. If
      <var class="Fa">on</var> points to a zero integer, redirect kernel console
      output back to the normal console. This is usually used on workstations to
      redirect kernel messages to a particular window.</dd>
  <dt id="TIOCMSET"><a class="permalink" href="#TIOCMSET"><code class="Dv">TIOCMSET</code></a>
    <var class="Fa">int *state</var></dt>
  <dd>The integer pointed to by <var class="Fa">state</var> contains bits that
      correspond to modem state. Following is a list of defined variables and
      the modem state they represent:
    <p class="Pp"></p>
    <dl class="Bl-tag Bl-compact">
      <dt>TIOCM_LE</dt>
      <dd>Line Enable.</dd>
      <dt>TIOCM_DTR</dt>
      <dd>Data Terminal Ready.</dd>
      <dt>TIOCM_RTS</dt>
      <dd>Request To Send.</dd>
      <dt>TIOCM_ST</dt>
      <dd>Secondary Transmit.</dd>
      <dt>TIOCM_SR</dt>
      <dd>Secondary Receive.</dd>
      <dt>TIOCM_CTS</dt>
      <dd>Clear To Send.</dd>
      <dt>TIOCM_CAR</dt>
      <dd>Carrier Detect.</dd>
      <dt>TIOCM_CD</dt>
      <dd>Carrier Detect (synonym).</dd>
      <dt>TIOCM_RNG</dt>
      <dd>Ring Indication.</dd>
      <dt>TIOCM_RI</dt>
      <dd>Ring Indication (synonym).</dd>
      <dt>TIOCM_DSR</dt>
      <dd>Data Set Ready.</dd>
    </dl>
    <p class="Pp">This call sets the terminal modem state to that represented by
        <var class="Fa">state</var>. Not all terminals may support this.</p>
  </dd>
  <dt id="TIOCMGET"><a class="permalink" href="#TIOCMGET"><code class="Dv">TIOCMGET</code></a>
    <var class="Fa">int *state</var></dt>
  <dd>Return the current state of the terminal modem lines as represented above
      in the integer pointed to by <var class="Fa">state</var>.</dd>
  <dt id="TIOCMBIS"><a class="permalink" href="#TIOCMBIS"><code class="Dv">TIOCMBIS</code></a>
    <var class="Fa">int *state</var></dt>
  <dd>The bits in the integer pointed to by <var class="Fa">state</var>
      represent modem state as described above, however the state is OR-ed in
      with the current state.</dd>
  <dt id="TIOCMBIC"><a class="permalink" href="#TIOCMBIC"><code class="Dv">TIOCMBIC</code></a>
    <var class="Fa">int *state</var></dt>
  <dd>The bits in the integer pointed to by <var class="Fa">state</var>
      represent modem state as described above, however each bit which is on in
      <var class="Fa">state</var> is cleared in the terminal.</dd>
</dl>
</section>
</section>
<section class="Sh">
<h1 class="Sh" id="IMPLEMENTATION_NOTES"><a class="permalink" href="#IMPLEMENTATION_NOTES">IMPLEMENTATION
  NOTES</a></h1>
<p class="Pp">The total number of input and output bytes through all terminal
    devices are available via the <var class="Va">kern.tty_nin</var> and
    <var class="Va">kern.tty_nout</var> read-only <a class="Xr">sysctl(8)</a>
    variables.</p>
</section>
<section class="Sh">
<h1 class="Sh" id="SEE_ALSO"><a class="permalink" href="#SEE_ALSO">SEE
  ALSO</a></h1>
<p class="Pp"><a class="Xr">stty(1)</a>, <a class="Xr">ioctl(2)</a>,
    <a class="Xr">ng_tty(4)</a>, <a class="Xr">pts(4)</a>,
    <a class="Xr">pty(4)</a>, <a class="Xr">termios(4)</a>,
    <a class="Xr">uart(4)</a>, <a class="Xr">getty(8)</a></p>
</section>
<section class="Sh">
<h1 class="Sh" id="HISTORY"><a class="permalink" href="#HISTORY">HISTORY</a></h1>
<p class="Pp">A console typewriter device <span class="Pa">/dev/tty</span> and
    asynchronous communication interfaces <span class="Pa">/dev/tty[0-5]</span>
    first appeared in <span class="Ux">Version&#x00A0;1 AT&amp;T
  UNIX</span>.</p>
</section>
<section class="Sh">
<h1 class="Sh" id="BUGS"><a class="permalink" href="#BUGS">BUGS</a></h1>
<p class="Pp">Before the Internet, serial ports were primarily used for inbound
    connections from terminals, either directly or through modems, these days
    serial ports are primarily used for outbound connections to devices, an
    evolution which unfortunately has spread the relevant documentation over
    three different manual pages: <a class="Xr">termios(4)</a>,
    <a class="Xr">uart(4)</a> and <a class="Xr">tty(4)</a>.</p>
</section>
</div>
<table class="foot">
  <tr>
    <td class="foot-date">April 3, 2022</td>
    <td class="foot-os">FreeBSD 15.0</td>
  </tr>
</table>