1 .\" Copyright 2002 Walter Harms <walter.harms@informatik.uni-oldenburg.de>
2 .\" and Andries Brouwer <aeb@cwi.nl>.
3 .\" Distributed under GPL.
5 .TH TTY_IOCTL 4 2002-12-29 "Linux" "Linux Programmer's Manual"
7 tty ioctl \- ioctls for terminals and serial lines
10 .BR "#include <termios.h>"
12 .BI "int ioctl(int " fd ", int " cmd ", ...);"
17 call for terminals and serial ports accepts many possible command arguments.
18 Most require a third argument, of varying type, here called \fIargp\fP
23 makes for non-portable programs. Use the POSIX interface described in
27 .SS "Get and Set Terminal Attributes"
29 .BI "TCGETS struct termios *" argp
31 .IR "tcgetattr(fd, argp)" .
33 Get the current serial port settings.
35 .BI "TCSETS const struct termios *" argp
37 .IR "tcsetattr(fd, TCSANOW, argp)" .
39 Set the current serial port settings.
41 .BI "TCSETSW const struct termios *" argp
43 .IR "tcsetattr(fd, TCSADRAIN, argp)" .
45 Allow the output buffer to drain, and
46 set the current serial port settings.
48 .BI "TCSETSF const struct termios *" argp
50 .IR "tcsetattr(fd, TCSAFLUSH, argp)" .
52 Allow the output buffer to drain, discard pending input, and
53 set the current serial port settings.
55 The following four ioctls are just like TCGETS, TCSETS, TCSETSW, TCSETSF,
56 except that they take a
59 .BR "struct termios *" .
61 .BI "TCGETA struct termio *" argp
63 .BI "TCSETA const struct termio *" argp
65 .BI "TCSETAW const struct termio *" argp
67 .BI "TCSETAF const struct termio *" argp
69 .SS "Locking the termios structure"
70 The termios structure of a tty can be locked. The lock is itself
71 a termios structure, with nonzero bits or fields indicating a
74 .BI "TIOCGLCKTRMIOS struct termios *" argp
75 Gets the locking status of the termios structure of
78 .BI "TIOCSLCKTRMIOS const struct termios *" argp
79 Sets the locking status of the termios structure of
80 the terminal. Only root can do this.
82 .SS "Get and Set Window Size"
83 Window sizes are kept in the kernel, but not used by the kernel
84 (except in the case of virtual consoles, where the kernel will
85 update the window size when the size of the virtual console changes,
86 e.g. by loading a new font).
88 .BI "TIOCGWINSZ struct winsize *" argp
91 .BI "TIOCSWINSZ const struct winsize *" argp
94 The struct used by these ioctls is defined as
98 unsigned short ws_row;
99 unsigned short ws_col;
100 unsigned short ws_xpixel; /* unused */
101 unsigned short ws_ypixel; /* unused */
105 When the window size changes, a SIGWINCH signal is sent to the
106 foreground process group.
108 .SS "Sending a Break"
110 .BI "TCSBRK int " arg
112 .IR "tcsendbreak(fd, arg)" .
114 If the terminal is using asynchronous serial data transmission, and
116 is zero, then send a break (a stream of zero bits) for between
117 0.25 and 0.5 seconds. If the terminal is not using asynchronous
118 serial data transmission, then either a break is sent, or the function
119 returns without doing anything.
122 is nonzero, nobody knows what will happen.
124 (SVR4, UnixWare, Solaris, Linux treat
125 .I "tcsendbreak(fd,arg)"
132 as a multiplier, and sends a stream of bits
134 times as long as done for zero
138 (when nonzero) as a timeinterval measured in milliseconds.
142 .BI "TCSBRKP int " arg
143 So-called "POSIX version" of TCSBRK. It treats nonzero
145 as a timeinterval measured in deciseconds, and does nothing
146 when the driver does not support breaks.
149 Turn break on, that is, start sending zero bits.
152 Turn break off, that is, stop sending zero bits.
154 .SS "Software flow control"
156 .BI "TCXONC int " arg
158 .IR "tcflow(fd, arg)" .
162 for the argument values TCOOFF, TCOON, TCIOFF, TCION.
164 .SS "Buffer count and flushing"
166 .BI "FIONREAD int *" argp
167 Get the number of bytes in the input buffer.
169 .BI "TIOCINQ int *" argp
172 .BI "TIOCOUTQ int *" argp
173 Get the number of bytes in the output buffer.
175 .BI "TCFLSH int " arg
177 .IR "tcflush(fd, arg)" .
181 for the argument values TCIFLUSH, TCOFLUSH, TCIOFLUSH.
185 .BI "TIOCSTI const char *" argp
186 Insert the given byte in the input queue.
188 .SS "Redirecting console output"
191 Redirect output that would have gone to
195 to the given tty. If that was a pty master, send it to the slave.
196 Anybody can do this as long as the output was not redirected yet.
197 If it was redirected already EBUSY is returned,
198 but root may stop redirection by using this ioctl with
205 .SS "Controlling tty"
207 .BI "TIOCSCTTY int " arg
208 Make the given tty the controlling tty of the current process.
209 The current process must be a session leader and not have a
210 controlling tty already. If this tty is already the controlling tty
211 of a different session group then the ioctl fails with EPERM,
212 unless the caller is root and
214 equals 1, in which case the tty is stolen, and all processes that had
215 it as controlling tty lose it.
218 If the given tty was the controlling tty of the current process,
219 give up this controlling tty. If the process was session leader,
220 then send SIGHUP and SIGCONT to the foreground process group
221 and all processes in the current session lose their controlling tty.
223 .SS "Process group and session ID"
225 .BI "TIOCGPGRP pid_t *" argp
226 When successful, equivalent to
227 .IR "*argp = tcgetpgrp(fd)" .
229 Get the process group ID of the foreground proces group on this tty.
231 .BI "TIOCSPGRP const pid_t *" argp
233 .IR "tcsetpgrp(fd, *argp)" .
235 Set the foreground process group id of this tty.
237 .BI "TIOCGSID pid_t *" argp
238 Get the session ID of the given tty. This will fail with ENOTTY
239 in case the tty is not a master pty and not our controlling tty. Strange.
244 Put the tty into exclusive mode.
247 operations on the terminal are permitted.
248 (They will fail with EBUSY, except for root.)
251 Disable exclusive mode.
253 .SS "Line discipline"
255 .BI "TIOCGETD int *" argp
256 Get the line discipline of the tty.
258 .BI "TIOCSETD const int *" argp
259 Set the line discipline of the tty.
261 .SS "Pseudo-tty ioctls"
263 .BI "TIOCPKT const int *" argp
266 is nonzero) or disable packet mode.
267 Can be applied to the master side of a pseudotty only (and will return
268 ENOTTY otherwise). In packet mode, each subsequent
270 will return a packet that either contains a single nonzero control byte,
271 or has a single zero byte followed by data written on the slave side of
272 the pty. If the first byte is not TIOCPKT_DATA (0), it is an OR of one
273 or more of the following bits:
276 TIOCPKT_FLUSHREAD The read queue for the terminal is flushed.
277 TIOCPKT_FLUSHWRITE The write queue for the terminal is flushed.
278 TIOCPKT_STOP Output to the terminal is stopped.
279 TIOCPKT_START Output to the terminal is restarted.
280 TIOCPKT_DOSTOP t_stopc is `^S' and t_startc is `^Q'.
281 TIOCPKT_NOSTOP the start and stop characters are not `^S/^Q'.
284 While this mode is in use, the presence
285 of control status information to be read
286 from the master side may be detected by a
288 for exceptional conditions.
294 to implement a remote-echoed, locally `^S/^Q' flow-controlled remote login.
296 The BSD ioctls TIOCSTOP, TIOCSTART, TIOCUCNTL, TIOCREMOTE
297 have not been implemented under Linux.
301 .BI "TIOCMGET int *" argp
302 get the status of modem bits.
304 .BI "TIOCMSET const int *" argp
305 set the status of modem bits.
307 .BI "TIOCMBIC const int *" argp
308 clear the indicated modem bits.
310 .BI "TIOCMBIS const int *" argp
311 set the indicated modem bits.
313 Bits used by these four ioctls:
316 TIOCM_LE DSR (data set ready/line enable)
317 TIOCM_DTR DTR (data terminal ready)
318 TIOCM_RTS RTS (request to send)
319 TIOCM_ST Secondary TXD (transmit)
320 TIOCM_SR Secondary RXD (receive)
321 TIOCM_CTS CTS (clear to send)
322 TIOCM_CAR DCD (data carrier detect)
323 TIOCM_CD see TIOCM_CAR
325 TIOCM_RI see TIOCM_RNG
326 TIOCM_DSR DSR (data set ready)
329 .SS "Marking a line as local"
331 .BI "TIOCGSOFTCAR int *" argp
332 ("Get software carrier flag")
333 Get the status of the CLOCAL flag in the c_cflag field of the
336 .BI "TIOCSSOFTCAR const int *" argp
337 ("Set software carrier flag")
338 Set the CLOCAL flag in the termios structure when
340 is nonzero, and clear it otherwise.
342 If the CLOCAL flag for a line is off, the hardware carrier detect (DCD)
343 signal is significant, and an
345 of the corresponding tty will block until DCD is asserted,
346 unless the O_NONBLOCK flag is given.
347 If CLOCAL is set, the line behaves as if DCD is always asserted.
348 The software carrier flag is usually turned on for local devices,
349 and is off for lines with modems.
352 For the TIOCLINUX ioctl, see
353 .BR console_ioctl (4).
355 .SS "Kernel debugging"
357 .BR "#include <linux/tty.h>"
360 .BI "TIOCTTYGSTRUCT struct tty_struct *" argp
361 Get the tty_struct corresponding to
364 .\" .SS "Serial info"
366 .\" .BR "#include <linux/serial.h>"
369 .\" .BI "TIOCGSERIAL struct serial_struct *" argp
372 .\" .BI "TIOCSSERIAL const struct serial_struct *" argp
378 system call returns 0 on success. On error it returns \-1 and sets
388 Invalid command parameter.
391 Insufficient permission.
397 Check the condition of DTR on the serial port.
402 #include <sys/ioctl.h>
407 fd = open("/dev/ttyS0", O_RDONLY);
408 ioctl(fd, TIOCMGET, &serial);
409 if (serial & TIOCM_DTR)
410 puts("TIOCM_DTR is not set");
412 puts("TIOCM_DTR is set");
420 .BR console_ioctl (4)
422 .\" FIONBIO const int *
425 .\" FIOASYNC const int *
427 .\" TIOCSERCONFIG void
428 .\" TIOCSERGWILD int *
429 .\" TIOCSERSWILD const int *
430 .\" TIOCSERGSTRUCT struct async_struct *
431 .\" TIOCSERGETLSR int *
432 .\" TIOCSERGETMULTI struct serial_multiport_struct *
433 .\" TIOCSERSETMULTI const struct serial_multiport_struct *
434 .\" TIOCGSERIAL, TIOCSSERIAL (see above)