hardware-console-terminal-tty-pty
Terminal
Generally speaking a terminal is a relatively dumb electromechanical device with an input interface (like a keyboard) and an output interface (like a display or sheet of paper).
The computer has an UART driver to read for the hardware device. The sequence of characters is passed to TTY driver which applies the line discipline. The line discipline is in charge of converting special characters (like end of line, backspaces), and echoing what has been received back to the teletype, so that the user can see what it has been typed (line disciplines will be discussed in the next post of the series).
The words terminal and TTY device are basically interchangeable as they mean the same thing.
Serial Terminal
A serial port terminal (Serial Port Terminal) is a terminal device connected using a serial port of a computer
. The computer treats each serial port as a character device. For a while, these serial port devices were often called terminal devices, because at that time its greatest use was to connect terminals. The device names corresponding to these serial ports are /dev/ttyS0 /dev/ttyS1 etc.
terminal emulator(TTY driver in kernel)
Let’s move to more recent times. Computers started becoming smaller and smaller, with everything packed in one single box.
For the first time the terminal was not a physical device connected via UART to the computer
. The terminal became a computer program in the kernel which would send characters directly to the TTY driver, read from it and print to the screen.
it listens for events coming from the keyboard and sends it down to the driver. The difference is that there is no physical device or cable which is connected to the TTY driver.
If you run a Linux OS on your machine press Ctrl+Alt+F1. You’ll get a TTY emulated by the kernel! You can get other TTYs by pressing Ctrl+Alt with the function keys from (F2 to F6), you can login on different TTYs, after that run bash shell inside that TTY. different login different TTY
But there is only one console(/dev/console) for a computer, if you write message to console(/dev/console), displayer will show it to you.
1 | $ echo "hello" >/dev/console |
In Linux systems, computer monitors are often called console terminals (Console). It emulates a terminal of type Linux (TERM = Linux), and there are some device special files associated with it: tty0, tty1, tty2, etc. When you log in on the console, tty1 is used. When using Alt + [F1-F6] key combination, we can switch to tty2, tty3, etc. tty1–tty6, etc. are called virtual terminals
, and tty0 is an alias of the currently used virtual terminal, and the information generated by the system will be sent to the terminal (also called console terminal at this time). Therefore, no matter which virtual terminal is currently being used, system information will be sent to the console terminal. You can log in to different virtual terminals, thus allowing the system to have several different sessions at the same time.
Shell
Shells are user space applications
that use the kernel API in just the same way as it is used by other application programs. A shell manages the user–system interaction by prompting users for input, interpreting their input, and then handling an output from the underlying operating system (much like a read–eval–print loop, REPL).
Bash, Zsh, Fish and sh are all different flavors of shells.
PTY(user land program)
If we remotely telnet to the host or use xterm, do we also need a terminal interaction? Yes, this is the virtual terminal pty (pseudo-tty) which runs in user land. while pts (pseudo-terminal slave) is the implementation method of pty
, and ptmx (pseudo-terminal master ) Used in conjunction with pty.