What is the difference between the Terminal and Shell and where does the Console come into play? What about TTY and PTY abbreviations? Read on to understand the differences.
Brief Course in History
To better understand the terminology and the concepts, we need to take a closer look at the history of human-computer interfaces. First, there was the Tele-Typewriter, or "Teletype" (TTY). Initially, teleprinters were used in telegraphy. Electrical telegraphy had been developed in the late 1830s and 1840s when communication was done over simpler Morse key equipment that was handled by skilled telegraph operators. The introduction of teleprinters replaced telegraph operators with typists, and machines were now communicating faster via Baudot code.
With the development of computers in the 1950s, teleprinters were used as a way to send typed data to a computer. The characters that the operator typed were buffered locally and sent from the teleprinter to a nearby mini or mainframe computer as a series of signals along an electrical cable (e.g., RS-232 cable) at 10 characters per second (110 baud/bits per second – bps). As a response, the computer would typically transmit a line of data, which would be printed on paper.
In the 1960s, terminals replaced the traditional teleprinters. Terminals are modernized teleprinters with Cathode Ray Tube (CRT) displays instead of printers. These were considered "dumb terminals," and they had just enough computer power required for the following:
Accept text input via the keyboard
Buffer input text one line at a time (enabling local editing before sending)
Send/receive text via serial communications
Display received text on the terminal’s display
Terminals rapidly became the primary devices used to operate mini, mainframe, and server computers. Then, in the mid-1980s, PCs started getting more powerful and affordable, replacing terminal devices. Many of the early PCs had a terminal application that could open a connection to the PC’s RS-232 serial port and exchange data with the machine that was listening on the other end. With the development of the Graphical User Interface, users could now simultaneously run multiple applications, including terminal applications. To understand how these concepts work in modern operating systems, let's cover them one by one.
Linux Console
The Linux console is a system console internal to the Linux kernel. A system console is the device that receives all kernel messages and warnings and allows logins in single-user mode.
Virtual Terminal(TTY)
Also known as a Virtual Terminal (VT) or Virtual Console (VC), it is implemented using the /dev/*
device file, which provides interaction with the Linux console by handling input (usually a keyboard) and output (usually a screen).
When the system boots, the kernel initializes several virtual terminals (accessible using Ctrl + Alt + F1 to F6, or more, depending on configuration). Each virtual terminal is associated with a device like /dev/tty1
, /dev/tty2
, etc. On each virtual terminal, a getty
process is run, which in turn runs /bin/login
to authenticate a user. After authentication, a shell will be run. Virtual terminals are supported at the Linux kernel level.
A virtual terminal is one of the devices that can be used as a system console, others being: serial port, USB serial port, VGA in text-mode, and framebuffer.
Pseudo Terminal(PTY)
With the developments in general computing, a new problem was introduced: How can a terminal speak to another CLI application on the same machine? And, of course, you can’t use a cable between the two applications running on the same computer. In Unix, this problem was solved by the introduction of the Pseudo Terminal (PTY) and terminal emulators.
As mentioned before, PCs used the RS-232 serial port in the beginning to communicate with the server. Unix systems also provided /dev/*
device files for them. With PTY, these device files are themselves emulated by a pair of devices:
Master: Provides means by which a terminal emulator process controls the slave.
Slave: Emulates a hardware serial port device and is used by command-line applications (e.g., shells like Cmd, PowerShell, and Bash) as a process to read/write data back from/to the master endpoint.
When the terminal emulator sends text and/or control commands (encoded as text) to the master device, the text is relayed to the associated slave device. Text emitted by the application is sent to the slave and is then routed back to the master and thus to the terminal emulator. Data is always sent/received asynchronously.
The slave pseudo-device emulates the behavior of a physical terminal device and converts command characters into POSIX signals. For example:
User types CTRL+C into the terminal emulator.
ASCII value of CTRL+C (0x03) is sent via the master.
0x03 is received by the slave and removed from the input stream.
SIGINT signal is generated.
Terminal Emulator
Terminal emulators are a software version of terminal devices. They emulate the functions of the hardware terminals on a PC. A terminal emulator inside a graphical user interface is often called a terminal window. Examples are xterm, PuTTY, and so on.
TTY vs PTY
So, what is the difference between TTY and PTY?
Virtual terminals or TTYs are implemented by the VT (virtual terminal) subsystem of the Linux kernel and do not rely on any user-space software - they work entirely within the core of the operating system.
On the other hand, PTY is a user-space process that emulates a terminal and is typically used in a graphical display environment. Multiple PTYs can be allocated on request.
Shell
A shell is a command-line interpreter that provides a command-line interface for the operating system. A CLI accepts input typed in by the operator and performs the requested commands.
For example:
echo Hello
writes the text "Hello" to the output device (e.g., screen).dir
in CMD orls
in PowerShell or Bash lists the contents of the current directory.
In UNIX/Linux, there are numerous shells, including Korn shell (ksh), C shell (csh), Bourne Shell (sh), Bourne Again Shell (bash), etc.
What about Windows?
The first Microsoft command-line interpreter was COMMAND.COM, used in MS-DOS. Then, in Windows NT, cmd.exe was designed to be compatible with legacy MS-DOS batch scripts and added several additional commands. In 2006, Microsoft released Windows PowerShell, a modern object-based command-line shell inspired by the features of other shells.
Historically, in Windows, shells like cmd.exe and PowerShell are command-line clients. All command-line clients are attached to a console server, and that server is conhost.exe. ConHost is not only responsible for being a console server, but it also draws the actual terminal window in which these applications run. When cmd or PowerShell is launched, conhost.exe is actually "hosting" these console applications.
Since Windows 10, Microsoft has been moving towards the Unix/Linux model, introducing a Windows Pseudo Console called ConPTY, which sends and receives text as an alternative to the old API. In the new command-line infrastructure, ConHost's ConPTY sits between new console applications like Windows Terminal and the old Windows Console API, enabling both approaches to work.
Resources: