Linux – /dev/console Points to tty0 Explained

deviceslinuxtty

I've been trying to understand the /dev/console device, but there are a few things I'm not clear on:

  1. What is the purpose of this device? From what I can gather it's just a place for the kernel to display messages, is that right?

  2. The virtual terminal that is assigned as the console isn't allowed to have job control. Why? Is that just because the kernel is trying to stop you from running anything else in the place that it needs to print system messages?

  3. For me, /dev/console seems to point to tty0, the current virtual console. I found this based on some simple testing and it seems to be a fairly common configuration. However, to me this indicates that tty0 should have job control disabled, which would mean that all consoles should have job control disabled, which would be bad. It's giving me a headache just thinking about it. Also, if tty0 is the console, then shouldn't I be getting kernel messages on the current terminal instead of just on tty1?

Best Answer

This book gives a good introduction to Linux ttys, and fgreping for register_console in Linux kernel’s drivers/char/*.c shows what’s going on with Linux console. There are many implementations of the system console available in the Linux kernel. A specific Linux installation can decide which particular device should serve as the console. It can be specified by passing kernel parameters on boot, or possibly other techniques exist. The implementation is the default one, and arguably de facto standard, but other exist as well, such as .

/dev/console has its own dedicated major:minor. Why? Because the kernel itself is a major user of the kernel device when reports emergency messages there. There is struct tty_driver *console_driver kernel object pointing to routines needed. Then why don’t provide an interface to it for userland programs as well? Have no idea whether is /dev/console, for the default setup, really equivalent to /dev/tty0, or there are some differences.

Now about job control at tty0. How could it be possible if tty0 doesn’t really emulate a terminal but only points to a tty that is currently active? Linux kernel prevents processes from attaching to tty0, a “device” that intermittently collides with tty1, … tty7 and so on. Since tty0 can’t control processes, there is no job control possible (by the way, for which legitimate purpose can tty0 feed a shell at all?). But this has nothing to do with possibility to control jobs that run on specific virtual consoles. Other numbered ttys are, in fact, legitimate terminals for any purpose of a console application.

Related Question