tty_ioctl   Début   Suivant   Sommaire   Préc.page.lue   Accueil
Section: Linux Programmer's Manual (4)
Updated: 2002-12-29
Sommaire  



NAME   Début   Précédent   Suivant   Sommaire   Préc.page.lue   Accueil
tty ioctl - ioctls for terminals and serial lines  



SYNOPSIS   Début   Précédent   Suivant   Sommaire   Préc.page.lue   Accueil
#include <termios.h>

int ioctl(int fd, int cmd, ...);  




DESCRIPTION   Début   Précédent   Suivant   Sommaire   Préc.page.lue   Accueil
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.  




Get and Set Terminal Attributes   Début   Précédent   Suivant   Sommaire   Préc.page.lue   Accueil
TCGETS        struct termios *argp
Equivalent to
tcgetattr(fd, argp).
Get the current serial port settings.
TCSETS const struct termios *argp
Equivalent to
tcsetattr(fd, TCSANOW, argp).
Set the current serial port settings.
TCSETSW        const struct termios *argp
Equivalent to
tcsetattr(fd, TCSADRAIN, argp).
Allow the output buffer to drain, and set the current serial port settings.
TCSETSF        const struct termios *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 struct termio * instead of a struct termios *.

TCGETA    struct termio *argp
TCSETA        const struct termio *argp
TCSETAW       const struct termio *argp
TCSETAF       const struct termio *argp
 



Locking the termios structure   Début   Précédent   Suivant   Sommaire   Préc.page.lue   Accueil
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.
TIOCGLCKTRMIOS struct termios *argp
Gets the locking status of the termios structure of
the terminal.
TIOCSLCKTRMIOS const struct termios *argp
Sets the locking status of the termios structure of
the terminal. Only root can do this.
 



Get and Set Window Size   Début   Précédent   Suivant   Sommaire   Préc.page.lue   Accueil
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 window size when the size of the virtual console changes, for example, by loading a new font).
TIOCGWINSZ     struct winsize *argp
Get window size.
TIOCSWINSZ     const struct winsize *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 foreground process group.  




Sending a Break   Début   Précédent   Suivant   Sommaire   Préc.page.lue   Accueil
TCSBRK        int 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 asynchronous 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.)

TCSBRKP int 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.
TIOCSBRK       void
Turn break on, that is, start sending zero bits.
TIOCCBRK       void
Turn break off, that is, stop sending zero bits.
 



Software flow control   Début   Précédent   Suivant   Sommaire   Préc.page.lue   Accueil
TCXONC        int arg
Equivalent to
tcflow(fd, arg).
See tcflow(3) for the argument values TCOOFF, TCOON, TCIOFF, TCION.
 



Buffer count and flushing   Début   Précédent   Suivant   Sommaire   Préc.page.lue   Accueil
FIONREAD      int *argp
Get the number of bytes in the input buffer.
TIOCINQ        int *argp
Same as
FIONREAD.
TIOCOUTQ    int *argp
Get the number of bytes in the output buffer.
TCFLSH int arg
Equivalent to
tcflush(fd, arg).
See tcflush(3) for the argument values TCIFLUSH, TCOFLUSH, TCIOFLUSH.
 



Faking input   Début   Précédent   Suivant   Sommaire   Préc.page.lue   Accueil
TIOCSTI       const char *argp
Insert the given byte in the input queue.
 



Redirecting console output   Début   Précédent   Suivant   Sommaire   Préc.page.lue   Accueil
TIOCCONS      void
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 pointing at /dev/console or /dev/tty0.
 



Controlling tty   Début   Précédent   Suivant   Sommaire   Préc.page.lue   Accueil
TIOCSCTTY     int arg
Make the given tty the controlling tty of the calling process.
The calling process must be a session leader and not have a controlling 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.
TIOCNOTTY       void
If the given tty was the controlling tty of the calling 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.
 



Process group and session ID   Début   Précédent   Suivant   Sommaire   Préc.page.lue   Accueil
TIOCGPGRP     pid_t *argp
When successful, equivalent to
*argp = tcgetpgrp(fd).
Get the process group ID of the foreground process group on this tty.
TIOCSPGRP      const pid_t *argp
Equivalent to
tcsetpgrp(fd, *argp).
Set the foreground process group ID of this tty.
TIOCGSID       pid_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.
 



Exclusive mode   Début   Précédent   Suivant   Sommaire   Préc.page.lue   Accueil
TIOCEXCL      void
Put the tty into exclusive mode.
No further open(2) operations on the terminal are permitted. (They will fail with EBUSY, except for root.)
TIOCNXCL       void
Disable exclusive mode.
 



Line discipline   Début   Précédent   Suivant   Sommaire   Préc.page.lue   Accueil
TIOCGETD      int *argp
Get the line discipline of the tty.
TIOCSETD       const int *argp
Set the line discipline of the tty.
 



Pseudo-tty ioctls   Début   Précédent   Suivant   Sommaire   Préc.page.lue   Accueil
TIOCPKT       const int *argp
Enable (when
*argp is nonzero) or disable packet mode. Can be applied to the master side of a pseudo-terminal 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 byte containing zero ('' ') 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 information 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.

 



Modem control   Début   Précédent   Suivant   Sommaire   Préc.page.lue   Accueil
TIOCMGET      int *argp
get the status of modem bits.
TIOCMSET       const int *argp
set the status of modem bits.
TIOCMBIC       const int *argp
clear the indicated modem bits.
TIOCMBIS       const int *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)
 



Marking a line as local   Début   Précédent   Suivant   Sommaire   Préc.page.lue   Accueil
TIOCGSOFTCAR  int *argp
("Get software carrier flag")
Get the status of the CLOCAL flag in the c_cflag field of the termios structure.
TIOCSSOFTCAR   const int *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.  




Linux-specific   Début   Précédent   Suivant   Sommaire   Préc.page.lue   Accueil
For the TIOCLINUX ioctl, see console_ioctl(4).  



Kernel debugging   Début   Précédent   Suivant   Sommaire   Préc.page.lue   Accueil
#include <linux/tty.h>
TIOCTTYGSTRUCT      struct tty_struct *argp
Get the
tty_struct corresponding to fd.
 



RETURN VALUE   Début   Précédent   Suivant   Sommaire   Préc.page.lue   Accueil
The ioctl() system call returns 0 on success. On error it returns -1 and sets errno appropriately.  



ERRORS   Début   Précédent   Suivant   Sommaire   Préc.page.lue   Accueil
EINVAL
Invalid command parameter.
ENOIOCTLCMD
Unknown command.
ENOTTY
Inappropriate fd.
EPERM
Insufficient permission.
 



EXAMPLE   Début   Précédent   Suivant   Sommaire   Préc.page.lue   Accueil
Check the condition of DTR on the serial port.

#include <termios.h>
#include <fcntl.h>
#include <sys/ioctl.h>

int
main(void)
{
    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);
}
 



SEE ALSO   Début   Précédent   Suivant   Sommaire   Préc.page.lue   Accueil
ioctl(2), termios(3), console_ioctl(4), pty(7)  



COLOPHON   Début   Précédent   Suivant   Sommaire   Préc.page.lue   Accueil
This page is part of release 2.78 of the Linux man-pages project. A description of the project, and information about reporting bugs, can be found at http://www.kernel.org/doc/man-pages/.


 



Sommaire   Début   Suivant   Sommaire   Préc.page.lue   Accueil
NAME
SYNOPSIS
DESCRIPTION
Get and Set Terminal Attributes
Locking the termios structure
Get and Set Window Size
Sending a Break
Software flow control
Buffer count and flushing
Faking input
Redirecting console output
Controlling tty
Process group and session ID
Exclusive mode
Line discipline
Pseudo-tty ioctls
Modem control
Marking a line as local
Linux-specific
Kernel debugging
RETURN VALUE
ERRORS
EXAMPLE
SEE ALSO
COLOPHON

Table des mots clés   Début   Suivant   Sommaire   Préc.page.lue   Accueil
EINVALERRORS
ENOIOCTLCMDERRORS
ENOTTYERRORS
EPERMERRORS
FIONREAD      int *argpBuffer count and flushing
TCFLSH int argBuffer count and flushing
TCGETA    struct termio *argpGet and Set Terminal Attributes
TCGETS        struct termios *argpGet and Set Terminal Attributes
TCSBRK        int argSending a Break
TCSBRKP int argSending a Break
TCSETA        const struct termio *argpGet and Set Terminal Attributes
TCSETAF       const struct termio *argpGet and Set Terminal Attributes
TCSETAW       const struct termio *argpGet and Set Terminal Attributes
TCSETS const struct termios *argpGet and Set Terminal Attributes
TCSETSF        const struct termios *argpGet and Set Terminal Attributes
TCSETSW        const struct termios *argpGet and Set Terminal Attributes
TCXONC        int argSoftware flow control
TIOCCBRK       voidSending a Break
TIOCCONS      voidRedirecting console output
TIOCEXCL      voidExclusive mode
TIOCGETD      int *argpLine discipline
TIOCGLCKTRMIOS struct termios *argpLocking the termios structure
TIOCGPGRP     pid_t *argpProcess group and session ID
TIOCGSID       pid_t *argpProcess group and session ID
TIOCGSOFTCAR  int *argpMarking a line as local
TIOCGWINSZ     struct winsize *argpGet and Set Window Size
TIOCINQ        int *argpBuffer count and flushing
TIOCMBIC       const int *argpModem control
TIOCMBIS       const int *argpModem control
TIOCMGET      int *argpModem control
TIOCMSET       const int *argpModem control
TIOCNOTTY       voidControlling tty
TIOCNXCL       voidExclusive mode
TIOCOUTQ    int *argpBuffer count and flushing
TIOCPKT       const int *argpPseudo-tty ioctls
TIOCSBRK       voidSending a Break
TIOCSCTTY     int argControlling tty
TIOCSETD       const int *argpLine discipline
TIOCSLCKTRMIOS const struct termios *argpLocking the termios structure
TIOCSPGRP      const pid_t *argpProcess group and session ID
TIOCSSOFTCAR   const int *argpMarking a line as local
TIOCSTI       const char *argpFaking input
TIOCSWINSZ     const struct winsize *argpGet and Set Window Size
TIOCTTYGSTRUCT      struct tty_struct *argpKernel debugging



Ce document a été créé par man2html suivi de man2html.pl, le 17/10/2008 17:51:44, en utilisant les pages de 'man'.
 

Valid HTML 4.01 Transitional