What is ttys?

Understanding ttys

A tty (short for "teletypewriter") is a terminal interface, traditionally a physical device, that allows users to interact with a Unix-like operating system. Today, it primarily refers to virtual terminal devices. ttys serve as a bridge between the user and the kernel, enabling input (commands) and output (text) to be exchanged.

Key aspects of ttys:

  • Types of ttys:

    • Physical Consoles: The directly attached keyboard and screen (e.g., /dev/console).
    • Virtual Terminals: Multiple logical terminals accessed via keyboard shortcuts (e.g., Ctrl+Alt+F1 through F7).
    • Pseudo-terminals (PTYs): Created by programs like xterm, gnome-terminal, or SSH to provide a terminal interface within a graphical environment or over a network. These are usually in /dev/pts/*.
    • Serial Ports: Older devices connecting via serial communication protocols.
  • Naming Convention: Ttys are typically represented as files in the /dev directory. For example, /dev/tty1, /dev/tty2, /dev/pts/0, etc.

  • Purpose:

    • Provide a text-based interface for user interaction.
    • Allow users to execute commands and run programs.
    • Display output from programs.
  • Controlling Terminal: Each process connected to a tty has a controlling terminal. Signals (like Ctrl+C) are sent to all processes in the foreground process group of the controlling terminal.

  • Utilities: Common commands for working with ttys:

    • tty: Prints the name of the current tty.
    • who: Shows who is logged in and on which ttys.
    • ps: Can be used to determine which processes are associated with a specific tty.
  • Importance: Ttys are fundamental to the operation of Unix-like systems, providing a crucial link between the user and the operating system kernel. They are essential for command-line interaction, scripting, and remote access.