Understanding Linux TTY, PTY, and PTS: A Complete Guide to Terminal Devices
This article explains the fundamental concepts of Linux terminal devices—including tty, pseudo‑terminal (pty), and virtual terminal (pts)—and details the various /dev entries such as serial ports, controlling terminals, console terminals, and their practical usage examples.
Basic Concepts
1> tty (terminal device): The term tty comes from teletypes, originally referring to electromechanical typewriters that communicated over serial lines. Modern terminals are character devices, commonly abbreviated as tty.
2> pty (pseudo‑terminal): When you remote‑login via telnet or use an xterm, a virtual terminal (pty) provides the interactive interface.
3> pts/ptmx (pts and ptmx): pts (pseudo‑terminal slave) works together with ptmx (pseudo‑terminal master) to implement a pty.
Terminal Device Files in /dev
1. Serial port terminal (/dev/ttySn): Serial terminals are character devices such as /dev/ttyS0, /dev/ttyS1, corresponding to COM1, COM2, etc. Data can be sent by redirecting output, e.g., echo test > /dev/ttyS1.
2. Pseudo‑terminal (/dev/pty/): A pseudo‑terminal consists of a master–slave pair; operations on the master are reflected on the slave. Examples are /dev/ptyp3 (master) and /dev/ttyp3 (slave).
3. Controlling terminal (/dev/tty): Represents the terminal that controls the current process. The command tty shows which device it is.
4. Console terminal (/dev/ttyn, /dev/console): The physical console (e.g., tty1‑tty6) is a virtual terminal; /dev/console is used by the OS to output messages, especially in single‑user mode.
5. Virtual terminal (/dev/pts/n): Used in graphical environments (X‑windows); for example, /dev/pts/1 appears when using a terminal emulator like Konsole.
6. Other types: Linux also defines various other terminal device files for specific hardware such as ISDN (/dev/ttyIn).
In summary, tty devices include virtual consoles, serial ports, and pseudo‑terminals. /dev/tty refers to the current terminal, so echo "hello" > /dev/tty prints directly to the active terminal.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
