4

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.

Tim
  • 101,790
  • No, they're not ptys. But where did you get the idea that there's only 7 of them? ls /dev/tty[0-9]* | wc -l returns 64 on my system. –  Nov 28 '18 at 07:30

2 Answers2

10

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/ttyn with 1 <= n <= 63. The current console is also addressed by /dev/console or /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

JdeBP
  • 68,745
  • Thanks. (1) "The current console is also addressed by /dev/console or /dev/tty0". If I am correct, /dev/tty is the device file of the controlling terminal of the current process session. Are /dev/console, /dev/tty0 and /dev/tty different? (2) Yes, there are /dev/ttyn with 1 <= n <= 63. 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? – Tim Nov 28 '18 at 12:06
  • Well … you said it, and only you to my knowledge. When you said it, in what sense did you mean? (-: – JdeBP Nov 28 '18 at 12:54
  • I can switch to virtual console #2, by Ctrl-Alt-F2. May I ask how I can switch to virtual console #20? – Tim Nov 28 '18 at 12:57
  • You don't need my permission to ask a question. (-: But you'll probably see it speedily closed as a duplicate of https://unix.stackexchange.com/questions/333895/ , https://unix.stackexchange.com/questions/82368/ , and their ilk. – JdeBP Nov 28 '18 at 13:03
  • You can be assured that I am just acting polite by saying in that way. (: – Tim Nov 28 '18 at 13:06
  • My recent posts are coming from my difficulty to understand the links you provided – Tim Nov 30 '18 at 17:22
  • https://unix.stackexchange.com/q/485156/674 and https://unix.stackexchange.com/q/485204/674 – Tim Nov 30 '18 at 23:31
0

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