I've been trying to understand the /dev/console device, but there are a few things I'm not clear on:
-
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?
-
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?
-
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
fgrep
ing forregister_console
in Linux kernel’sdrivers/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 tty implementation is the default one, and arguably de facto standard, but other exist as well, such as serial-console./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 isstruct 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 iftty0
doesn’t really emulate a terminal but only points to atty
that is currently active? Linux kernel prevents processes from attaching totty0
, a “device” that intermittently collides withtty1
, …tty7
and so on. Sincetty0
can’t control processes, there is no job control possible (by the way, for which legitimate purpose cantty0
feed a shell at all?). But this has nothing to do with possibility to control jobs that run on specific virtual consoles. Other numberedtty
s are, in fact, legitimate terminals for any purpose of a console application.