Linux has 7 virtual consoles, which correspond to 7 device files /dev/tty[n].
Is a virtual console running as a process, just like a terminal emulator? (I am not sure. It seems a virtual console is part of the kernel, and if that is correct, it can’t be a process.)
Is a virtual console implemented based on pseudoterminal, just like a terminal emulator? (I guess no. Otherwise, a virtual console’s device file will be /dev/pts/[n], instead of /dev/tty[n])
Thanks.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
That is incorrect.
There’s a terminal emulator program built into the Linux kernel. It doesn’t manifest as a running process with open file handles. Nor does it require pseudo-terminal devices. It’s layered on top of the framebuffer and the input event subsystem, which it uses internal kernel interfaces to access. It presents itself to application-mode systems as a series of 63 (not 7) kernel virtual terminal devices, /dev/tty1 to /dev/tty63.
User-space virtual terminals are implemented using pseudo-terminal devices. Pseudo-terminal devices, kernel virtual terminal devices, and real terminal devices layered on top of serial ports are the three types of terminal device (as far as applications programs are concerned) in Linux.
Because of a lack of coördination, Linux documentation is now quite bad on this subject. There has been for several years no manual page for kernel virtual terminal devices on several Linux operating systems, although there are pages for the other two types of terminal device. This manual page would have explained the correct number or devices and their device file names and used to read:
A Linux system has up to 63 virtual consoles (character devices with major number 4 and minor number 1 to 63), usually called
/dev/ttynwith 1 <= n <= 63. The current console is also addressed by/dev/consoleor/dev/tty0, the character device with major number 4 and minor number 0.
Debian people noticed that Debian was missing a console(4) manual page in 2014, and switched to installing the one from the Linux Manpages Project, only for people in that same project to delete their console(4) manual page a year and a bit later in 2016 because “Debian and derivatives don’t install this page” and “Debian no longer carries it”.
Further reading
- https://unix.stackexchange.com/a/177209/5132
- https://unix.stackexchange.com/a/333922/5132
- Linux: Difference between /dev/console , /dev/tty and /dev/tty0
- What are TTYs >12 used for?
ttyS. Linux Programmers’ Manual. Michael Kerrisk. 1992-12-19.pty. Linux Programmers’ Manual. Michael Kerrisk. 2017-09-15.- https://dyn.manpages.debian.org/jessie/manpages/console.4.html
- https://dyn.manpages.debian.org/stretch/manpages/console.4.html
- https://dyn.manpages.debian.org/testing/manpages/console.4.html
- http://manpages.ubuntu.com/manpages/trusty/en/man4/console.4.html
- http://manpages.ubuntu.com/manpages/artful/en/man4/console.4.html
- http://manpages.ubuntu.com/manpages/bionic/en/man4/console.4.html
- http://manpages.ubuntu.com/manpages/cosmic/en/man4/console.4.html
- Vincent Lefevre (2014-12-27). manpages: some man pages have references to
console(4), which no longer exists. Debian bug #774022. - Dr. Tobias Quathamer (2016-01-05). “
console.4: Is now included in this package. (Closes: #774022)“. manpages 4.04-0.1. changelog. - Marko Myllynen (2016-01-07).
console(4) is out of date. Kernel bug #110481. - Michael Kerrisk (2016-03-15). “
console.4: Remove outdated page“. man-pages. kernel.org. - Jonathan de Boyne Pollard (2016). “Terminals“. nosh Guide. Softwares.
- Jonathan de Boyne Pollard (2018). Manual pages for Linux kernel virtual terminal devices. Proposals.
Method 2
When some says there are 7 virtual consoles in Linux, in what sense do
they mean? Do they mean there are only 7 accessible by key shortcuts?
In the sense that they are spawned / readily available. It was configured in /etc/inittab, by spawning several (a)gettys in a multiuser runlevel.
For once I cite pideins (getty.target sends me there):
By default this automatic spawning is done for the VTs up to VT6 only
(in order to be close to the traditional default configuration of
Linux systems)1
One VT is often used for GUI – may count or not.
systemd does it more subtle, but the result is quite the same. An orthogonal feeling, especially when you use the arrow keys to flip through the ttys.
chvt 20 puts me on a blank “terminal” (default systemd) — it needs some getty to activate it first. Then you address it like that, or turn your Fn keys into an organ. Or use Alt-arrow.
Is a virtual console running as a process
In a way yes. It needs a getty process to open a ttyX.
6314 tty2 Ss+ 0:00 /sbin/agetty -o -p -- u --noclear tty2 linux 6316 tty3 Ss+ 0:00 /sbin/agetty -o -p -- u --noclear tty3 linux 7408 tty5 Ss+ 0:00 /sbin/agetty -o -p -- u --noclear tty5 linux 7453 pts/1 S+ 0:00 grep getty
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0