TTY_IOCTL(4) Linux Programmer's Manual TTY_IOCTL(4)
NAME
tty ioctl - ioctls for terminals and serial lines
SYNOPSIS
#include<termios.h>
intioctl(int fd,int cmd,...);
DESCRIPTION
The ioctl() call for terminals and serial ports accepts many possible
command arguments. Most require a third argument, of varying type,
here called argp or arg.
Use of ioctl makes for non-portable programs. Use the POSIX interface
described in termios(3) whenever possible.
GetandSetTerminalAttributes
TCGETSstructtermios*argp
Equivalent to tcgetattr(fd, argp).
Get the current serial port settings.
TCSETSconststructtermios*argp
Equivalent to tcsetattr(fd, TCSANOW, argp).
Set the current serial port settings.
TCSETSWconststructtermios*argp
Equivalent to tcsetattr(fd, TCSADRAIN, argp).
Allow the output buffer to drain, and set the current serial
port settings.
TCSETSFconststructtermios*argp
Equivalent to tcsetattr(fd, TCSAFLUSH, argp).
Allow the output buffer to drain, discard pending input, and set
the current serial port settings.
The following four ioctls are just like TCGETS, TCSETS, TCSETSW,
TCSETSF, except that they take a structtermio* instead of a struct
termios*.
TCGETAstructtermio*argp
TCSETAconststructtermio*argp
TCSETAWconststructtermio*argp
TCSETAFconststructtermio*argp
Lockingthetermiosstructure
The termios structure of a tty can be locked. The lock is itself a
termios structure, with nonzero bits or fields indicating a locked
value.
TIOCGLCKTRMIOSstructtermios*argp
Gets the locking status of the termios structure of the termi-
nal.
TIOCSLCKTRMIOSconststructtermios*argp
Sets the locking status of the termios structure of the termi-
nal. Only root can do this.
GetandSetWindowSize
Window sizes are kept in the kernel, but not used by the kernel (except
in the case of virtual consoles, where the kernel will update the win-
dow size when the size of the virtual console changes, e.g. by loading
a new font).
TIOCGWINSZstructwinsize*argp
Get window size.
TIOCSWINSZconststructwinsize*argp
Set window size.
The struct used by these ioctls is defined as
struct winsize {
unsigned short ws_row;
unsigned short ws_col;
unsigned short ws_xpixel; /* unused */
unsigned short ws_ypixel; /* unused */
};
When the window size changes, a SIGWINCH signal is sent to the fore-
ground process group.
SendingaBreak
TCSBRKint arg
Equivalent to tcsendbreak(fd, arg).
If the terminal is using asynchronous serial data transmission,
and arg is zero, then send a break (a stream of zero bits) for
between 0.25 and 0.5 seconds. If the terminal is not using asyn-
chronous serial data transmission, then either a break is sent,
or the function returns without doing anything. When arg is
nonzero, nobody knows what will happen.
(SVR4, UnixWare, Solaris, Linux treat tcsendbreak(fd,arg) with
nonzero arg like tcdrain(fd). SunOS treats arg as a multiplier,
and sends a stream of bits arg times as long as done for zero
arg. DG-UX and AIX treat arg (when nonzero) as a timeinterval
measured in milliseconds. HP-UX ignores arg.)
TCSBRKPint arg
So-called "POSIX version" of TCSBRK. It treats nonzero arg as a
timeinterval measured in deciseconds, and does nothing when the
driver does not support breaks.
TIOCSBRKvoid
Turn break on, that is, start sending zero bits.
TIOCCBRKvoid
Turn break off, that is, stop sending zero bits.
Softwareflowcontrol
TCXONCint arg
Equivalent to tcflow(fd, arg).
See tcflow(3) for the argument values TCOOFF, TCOON, TCIOFF,
TCION.
Buffercountandflushing
FIONREADint*argp
Get the number of bytes in the input buffer.
TIOCINQint*argp
Same as FIONREAD.
TIOCOUTQint*argp
Get the number of bytes in the output buffer.
TCFLSHint arg
Equivalent to tcflush(fd, arg).
See tcflush(3) for the argument values TCIFLUSH, TCOFLUSH,
TCIOFLUSH.
Fakinginput
TIOCSTIconstchar*argp
Insert the given byte in the input queue.
Redirectingconsoleoutput
TIOCCONSvoid
Redirect output that would have gone to /dev/console or
/dev/tty0 to the given tty. If that was a pty master, send it to
the slave. Anybody can do this as long as the output was not
redirected yet. If it was redirected already EBUSY is returned,
but root may stop redirection by using this ioctl with fd point-
ing at /dev/console or /dev/tty0.
Controllingtty
TIOCSCTTYint arg
Make the given tty the controlling tty of the current process.
The current process must be a session leader and not have a con-
trolling tty already. If this tty is already the controlling tty
of a different session group then the ioctl fails with EPERM,
unless the caller is root and arg equals 1, in which case the
tty is stolen, and all processes that had it as controlling tty
lose it.
TIOCNOTTYvoid
If the given tty was the controlling tty of the current process,
give up this controlling tty. If the process was session leader,
then send SIGHUP and SIGCONT to the foreground process group and
all processes in the current session lose their controlling tty.
ProcessgroupandsessionID
TIOCGPGRPpid_t*argp
When successful, equivalent to *argp = tcgetpgrp(fd).
Get the process group ID of the foreground proces group on this
tty.
TIOCSPGRPconstpid_t*argp
Equivalent to tcsetpgrp(fd, *argp).
Set the foreground process group id of this tty.
TIOCGSIDpid_t*argp
Get the session ID of the given tty. This will fail with ENOTTY
in case the tty is not a master pty and not our controlling tty.
Strange.
Exclusivemode
TIOCEXCLvoid
Put the tty into exclusive mode. No further open(2) operations
on the terminal are permitted. (They will fail with EBUSY,
except for root.)
TIOCNXCLvoid
Disable exclusive mode.
Linediscipline
TIOCGETDint*argp
Get the line discipline of the tty.
TIOCSETDconstint*argp
Set the line discipline of the tty.
Pseudo-ttyioctls
TIOCPKTconstint*argp
Enable (when *argp is nonzero) or disable packet mode. Can be
applied to the master side of a pseudotty only (and will return
ENOTTY otherwise). In packet mode, each subsequent read(2) will
return a packet that either contains a single nonzero control
byte, or has a single zero byte followed by data written on the
slave side of the pty. If the first byte is not TIOCPKT_DATA
(0), it is an OR of one or more of the following bits:
TIOCPKT_FLUSHREAD The read queue for the terminal is flushed.
TIOCPKT_FLUSHWRITE The write queue for the terminal is flushed.
TIOCPKT_STOP Output to the terminal is stopped.
TIOCPKT_START Output to the terminal is restarted.
TIOCPKT_DOSTOP t_stopc is '^S' and t_startc is '^Q'.
TIOCPKT_NOSTOP the start and stop characters are not '^S/^Q'.
While this mode is in use, the presence of control status infor-
mation to be read from the master side may be detected by a
select(2) for exceptional conditions.
This mode is used by rlogin(1) and rlogind(8) to implement a
remote-echoed, locally '^S/^Q' flow-controlled remote login.
The BSD ioctls TIOCSTOP, TIOCSTART, TIOCUCNTL, TIOCREMOTE have
not been implemented under Linux.
Modemcontrol
TIOCMGETint*argp
get the status of modem bits.
TIOCMSETconstint*argp
set the status of modem bits.
TIOCMBICconstint*argp
clear the indicated modem bits.
TIOCMBISconstint*argp
set the indicated modem bits.
Bits used by these four ioctls:
TIOCM_LE DSR (data set ready/line enable)
TIOCM_DTR DTR (data terminal ready)
TIOCM_RTS RTS (request to send)
TIOCM_ST Secondary TXD (transmit)
TIOCM_SR Secondary RXD (receive)
TIOCM_CTS CTS (clear to send)
TIOCM_CAR DCD (data carrier detect)
TIOCM_CD see TIOCM_CAR
TIOCM_RNG RNG (ring)
TIOCM_RI see TIOCM_RNG
TIOCM_DSR DSR (data set ready)
Markingalineaslocal
TIOCGSOFTCARint*argp
("Get software carrier flag") Get the status of the CLOCAL flag
in the c_cflag field of the termios structure.
TIOCSSOFTCARconstint*argp
("Set software carrier flag") Set the CLOCAL flag in the termios
structure when *argp is nonzero, and clear it otherwise.
If the CLOCAL flag for a line is off, the hardware carrier detect (DCD)
signal is significant, and an open(2) of the corresponding tty will
block until DCD is asserted, unless the O_NONBLOCK flag is given. If
CLOCAL is set, the line behaves as if DCD is always asserted. The
software carrier flag is usually turned on for local devices, and is
off for lines with modems.
Linuxspecific
For the TIOCLINUX ioctl, see console_ioctl(4).
Kerneldebugging
#include<linux/tty.h>
TIOCTTYGSTRUCTstructtty_struct*argp
Get the tty_struct corresponding to fd.
RETURNVALUE
The ioctl() system call returns 0 on success. On error it returns -1
and sets errno appropriately.
ERRORS
ENOIOCTLCMD
Unknown command.
EINVAL Invalid command parameter.
EPERM Insufficient permission.
ENOTTY Inappropriate fd.
EXAMPLE
Check the condition of DTR on the serial port.
#include <termios.h>
#include <fcntl.h>
#include <sys/ioctl.h>
main() {
int fd, serial;
fd = open("/dev/ttyS0", O_RDONLY);
ioctl(fd, TIOCMGET, &serial);
if (serial & TIOCM_DTR)
puts("TIOCM_DTR is not set");
else
puts("TIOCM_DTR is set");
close(fd);
}
SEEALSO
ioctl(2), termios(3), console_ioctl(4)
Linux 2002-12-29 TTY_IOCTL(4)