| TTY(4) | Device Drivers Manual | TTY(4) | 
tty — general
    terminal interface
#include
    <sys/ioctl.h>
This section describes the interface to the terminal drivers in the system.
Each hardware terminal port on the system usually has a terminal special device file associated with it in the directory ``/dev/'' (for example, ``/dev/tty03''). 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 getty(8).) 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 ptys and provide the mechanism necessary to give users the same interface to the system when logging in over a network (using rlogin(1), or telnet(1) 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 tip(1)).
When an interactive user logs in, the system prepares the line to behave in a certain way (called a line discipline), the particular details of which is described in stty(1) at the command level, and in termios(4) 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.
All of the following operations are invoked using the ioctl(2) system call. Refer to that man page for a description of the request and argp parameters. In addition to the ioctl requests defined here, the specific line discipline in effect will define other requests specific to it (actually termios(4) defines them as function calls, not ioctl requests.) The following section lists the available ioctl requests. The name of the request, a description of its purpose, and the typed argp parameter (if any) are listed. For example, the first entry says
and would be called on the terminal associated with file descriptor zero by the following code fragment:
int pgrp; pgrp = getpgrp(); ioctl(0, TIOCSPGRP, &pgrp);
TIOCSETD
    int *ldiscTIOCGETD
    int *ldiscTIOCSBRK
    voidTIOCCBRK
    voidTIOCSDTR
    voidTIOCCDTR
    voidTIOCGPGRP
    int *tpgrptcgetattr()
      call.TIOCSPGRP
    int *tpgrptcsetattr()
      call.TIOCGETA
    struct termios *termtcgetattr() call.TIOCSETA
    struct termios *termtcsetattr() call with the
      TCSANOW option.TIOCSETAW
    struct termios *termtcsetattr() call
      with the TCSADRAIN option.TIOCSETAF
    struct termios *termtcsetattr() call with the
      TCSAFLUSH option.TIOCOUTQ
    int *numTIOCSTI
    char *cpTIOCNOTTY
    voidTIOCNOTTY on that file descriptor.
    The current system does not allocate a controlling
        terminal to a process on an
        open()
        call: there is a specific ioctl called TIOCSCTTY
        to make a terminal the controlling terminal. In addition, a program can
        fork()
        and call the
        setsid()
        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.
TIOCSTOP
    voidTIOCSTART
    voidTIOCSCTTY
    voidTIOCDRAIN
    voidTIOCGDRAINWAIT
    int *timeoutTIOCSDRAINWAIT
    int *timeoutTIOCEXCL
    voidTIOCNXCL
    voidTIOCFLUSH
    int *whatFREAD bit as defined in
      <sys/file.h>, then all
      characters in the input queue are cleared. If it contains the
      FWRITE 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 FREAD and
      FWRITE bits were set (i.e., clears both
    queues).TIOCGWINSZ
    struct winsize *ws<sys/ioctl.h>.TIOCSWINSZ
    struct winsize *wsTIOCCONS
    int *onTIOCMSET
    int *stateThis call sets the terminal modem state to that represented by state. Not all terminals may support this.
TIOCMGET
    int *stateTIOCMBIS
    int *stateTIOCMBIC
    int *stateThe total number of input and output bytes through all terminal devices are available via the kern.tty_nin and kern.tty_nout read-only sysctl(8) variables.
| January 11, 2017 | Debian |