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 2008-10-29 "Linux" "Linux Programmer's Manual"
7 tty ioctl \- ioctls for terminals and serial lines
9 .B "#include <termios.h>"
11 .BI "int ioctl(int " fd ", int " cmd ", ...);"
15 call for terminals and serial ports accepts many possible command arguments.
16 Most require a third argument, of varying type, here called \fIargp\fP
21 makes for non-portable programs.
22 Use the POSIX interface described in
25 .SS "Get and Set Terminal Attributes"
27 .BI "TCGETS struct termios *" argp
29 .IR "tcgetattr(fd, argp)" .
31 Get the current serial port settings.
33 .BI "TCSETS const struct termios *" argp
35 .IR "tcsetattr(fd, TCSANOW, argp)" .
37 Set the current serial port settings.
39 .BI "TCSETSW const struct termios *" argp
41 .IR "tcsetattr(fd, TCSADRAIN, argp)" .
43 Allow the output buffer to drain, and
44 set the current serial port settings.
46 .BI "TCSETSF const struct termios *" argp
48 .IR "tcsetattr(fd, TCSAFLUSH, argp)" .
50 Allow the output buffer to drain, discard pending input, and
51 set the current serial port settings.
53 The following four ioctls are just like
58 except that they take a
61 .IR "struct termios *" .
63 .BI "TCGETA struct termio *" argp
65 .BI "TCSETA const struct termio *" argp
67 .BI "TCSETAW const struct termio *" argp
69 .BI "TCSETAF const struct termio *" argp
70 .SS "Locking the termios structure"
73 structure of a terminal can be locked.
76 structure, with non-zero bits or fields indicating a
79 .BI "TIOCGLCKTRMIOS struct termios *" argp
80 Gets the locking status of the
82 structure of the terminal.
84 .BI "TIOCSLCKTRMIOS const struct termios *" argp
85 Sets the locking status of the
87 structure of the terminal.
88 Only root (more precisely: a process with the
90 capability) can do this.
91 .SS "Get and Set Window Size"
92 Window sizes are kept in the kernel, but not used by the kernel
93 (except in the case of virtual consoles, where the kernel will
94 update the window size when the size of the virtual console changes,
95 for example, by loading a new font).
97 The following constants and structure are defined in
100 .BI "TIOCGWINSZ struct winsize *" argp
103 .BI "TIOCSWINSZ const struct winsize *" argp
106 The struct used by these ioctls is defined as
111 unsigned short ws_row;
112 unsigned short ws_col;
113 unsigned short ws_xpixel; /* unused */
114 unsigned short ws_ypixel; /* unused */
119 When the window size changes, a
121 signal is sent to the
122 foreground process group.
123 .SS "Sending a Break"
125 .BI "TCSBRK int " arg
127 .IR "tcsendbreak(fd, arg)" .
129 If the terminal is using asynchronous serial data transmission, and
131 is zero, then send a break (a stream of zero bits) for between
132 0.25 and 0.5 seconds.
133 If the terminal is not using asynchronous
134 serial data transmission, then either a break is sent, or the function
135 returns without doing anything.
138 is non-zero, nobody knows what will happen.
140 (SVr4, UnixWare, Solaris, Linux treat
141 .I "tcsendbreak(fd,arg)"
148 as a multiplier, and sends a stream of bits
150 times as long as done for zero
154 (when non-zero) as a time interval measured in milliseconds.
158 .BI "TCSBRKP int " arg
159 So-called "POSIX version" of
163 as a timeinterval measured in deciseconds, and does nothing
164 when the driver does not support breaks.
167 Turn break on, that is, start sending zero bits.
170 Turn break off, that is, stop sending zero bits.
171 .SS "Software flow control"
173 .BI "TCXONC int " arg
175 .IR "tcflow(fd, arg)" .
179 for the argument values
184 .SS "Buffer count and flushing"
186 .BI "FIONREAD int *" argp
187 Get the number of bytes in the input buffer.
189 .BI "TIOCINQ int *" argp
193 .BI "TIOCOUTQ int *" argp
194 Get the number of bytes in the output buffer.
196 .BI "TCFLSH int " arg
198 .IR "tcflush(fd, arg)" .
202 for the argument values
208 .BI "TIOCSTI const char *" argp
209 Insert the given byte in the input queue.
210 .SS "Redirecting console output"
213 Redirect output that would have gone to
217 to the given terminal.
218 If that was a pseudo-terminal master, send it to the slave.
219 In Linux before version 2.6.10,
220 anybody can do this as long as the output was not redirected yet;
221 since version 2.6.10, only root (a process with the
223 capability) may do this.
224 If output was redirected already
227 but redirection can be stopped by using this ioctl with
233 .SS "Controlling terminal"
235 .BI "TIOCSCTTY int " arg
236 Make the given terminal the controlling terminal of the calling process.
237 The calling process must be a session leader and not have a
238 controlling terminal already.
239 If this terminal is already the controlling terminal
240 of a different session group then the ioctl fails with
242 unless the caller is root (more precisely: has the
246 equals 1, in which case the terminal is stolen, and all processes that had
247 it as controlling terminal lose it.
250 If the given terminal was the controlling terminal of the calling process,
251 give up this controlling terminal.
252 If the process was session leader,
257 to the foreground process group
258 and all processes in the current session lose their controlling terminal.
259 .SS "Process group and session ID"
261 .BI "TIOCGPGRP pid_t *" argp
262 When successful, equivalent to
263 .IR "*argp = tcgetpgrp(fd)" .
265 Get the process group ID of the foreground process group on this terminal.
267 .BI "TIOCSPGRP const pid_t *" argp
269 .IR "tcsetpgrp(fd, *argp)" .
271 Set the foreground process group ID of this terminal.
273 .BI "TIOCGSID pid_t *" argp
274 Get the session ID of the given terminal.
277 in case the terminal is not a master pseudo-terminal
278 and not our controlling terminal.
283 Put the terminal into exclusive mode.
286 operations on the terminal are permitted.
289 except for root, that is, a process with the
294 Disable exclusive mode.
295 .SS "Line discipline"
297 .BI "TIOCGETD int *" argp
298 Get the line discipline of the terminal.
300 .BI "TIOCSETD const int *" argp
301 Set the line discipline of the terminal.
302 .SS "Pseudo-terminal ioctls"
304 .BI "TIOCPKT const int *" argp
307 is non-zero) or disable packet mode.
308 Can be applied to the master side of a pseudo-terminal only (and will return
311 In packet mode, each subsequent
313 will return a packet that either contains a single non-zero control byte,
314 or has a single byte containing zero (\(aq\0\(aq) followed by data
315 written on the slave side of the pseudo-terminal.
316 If the first byte is not
318 (0), it is an OR of one
319 or more of the following bits:
322 TIOCPKT_FLUSHREAD The read queue for the terminal is flushed.
323 TIOCPKT_FLUSHWRITE The write queue for the terminal is flushed.
324 TIOCPKT_STOP Output to the terminal is stopped.
325 TIOCPKT_START Output to the terminal is restarted.
326 TIOCPKT_DOSTOP The start and stop characters are \fB^S\fP/\fB^Q\fP.
327 TIOCPKT_NOSTOP The start and stop characters are not \fB^S\fP/\fB^Q\fP.
330 While this mode is in use, the presence
331 of control status information to be read
332 from the master side may be detected by a
334 for exceptional conditions.
340 to implement a remote-echoed,
341 locally \fB^S\fP/\fB^Q\fP flow-controlled remote login.
348 have not been implemented under Linux.
351 .BI "TIOCMGET int *" argp
352 get the status of modem bits.
354 .BI "TIOCMSET const int *" argp
355 set the status of modem bits.
357 .BI "TIOCMBIC const int *" argp
358 clear the indicated modem bits.
360 .BI "TIOCMBIS const int *" argp
361 set the indicated modem bits.
363 Bits used by these four ioctls:
366 TIOCM_LE DSR (data set ready/line enable)
367 TIOCM_DTR DTR (data terminal ready)
368 TIOCM_RTS RTS (request to send)
369 TIOCM_ST Secondary TXD (transmit)
370 TIOCM_SR Secondary RXD (receive)
371 TIOCM_CTS CTS (clear to send)
372 TIOCM_CAR DCD (data carrier detect)
373 TIOCM_CD see TIOCM_CAR
375 TIOCM_RI see TIOCM_RNG
376 TIOCM_DSR DSR (data set ready)
378 .SS "Marking a line as local"
380 .BI "TIOCGSOFTCAR int *" argp
381 ("Get software carrier flag")
382 Get the status of the CLOCAL flag in the c_cflag field of the
386 .BI "TIOCSSOFTCAR const int *" argp
387 ("Set software carrier flag")
388 Set the CLOCAL flag in the
392 is non-zero, and clear it otherwise.
396 flag for a line is off, the hardware carrier detect (DCD)
397 signal is significant, and an
399 of the corresponding terminal will block until DCD is asserted,
405 is set, the line behaves as if DCD is always asserted.
406 The software carrier flag is usually turned on for local devices,
407 and is off for lines with modems.
412 .BR console_ioctl (4).
413 .SS "Kernel debugging"
414 .B "#include <linux/tty.h>"
416 .BI "TIOCTTYGSTRUCT struct tty_struct *" argp
422 .\" .SS "Serial info"
423 .\" .BR "#include <linux/serial.h>"
426 .\" .BI "TIOCGSERIAL struct serial_struct *" argp
429 .\" .BI "TIOCSSERIAL const struct serial_struct *" argp
434 system call returns 0 on success.
435 On error it returns \-1 and sets
441 Invalid command parameter.
451 Insufficient permission.
453 Check the condition of DTR on the serial port.
458 #include <sys/ioctl.h>
465 fd = open("/dev/ttyS0", O_RDONLY);
466 ioctl(fd, TIOCMGET, &serial);
467 if (serial & TIOCM_DTR)
468 puts("TIOCM_DTR is not set");
470 puts("TIOCM_DTR is set");
477 .BR console_ioctl (4),
480 .\" FIONBIO const int *
483 .\" FIOASYNC const int *
485 .\" TIOCSERCONFIG void
486 .\" TIOCSERGWILD int *
487 .\" TIOCSERSWILD const int *
488 .\" TIOCSERGSTRUCT struct async_struct *
489 .\" TIOCSERGETLSR int *
490 .\" TIOCSERGETMULTI struct serial_multiport_struct *
491 .\" TIOCSERSETMULTI const struct serial_multiport_struct *
492 .\" TIOCGSERIAL, TIOCSSERIAL (see above)