Q:
On a Linux system, what is the difference between /dev/console , /dev/tty and /dev/tty0 ?
What is their respective use? How do they compare?
A:From the documentation:
/dev/tty Current TTY device
/dev/console System console
/dev/tty0 Current virtual console
In the good old days /dev/console was System Administrator console. And TTYs were users' serial devices attached to a server. Now /dev/console and /dev/tty0 represent current display and usually are the same. You can override it for example by adding console=ttyS0 to grub.conf. After that your /dev/tty0 is a monitor and /dev/console is /dev/ttyS0.
An exercise to show the difference between /dev/tty and /dev/tty0:
Switch to the 2nd console by pressing Ctrl+Alt+F2. Login as root. Type sleep 5; echo tty0 > /dev/tty0. Press Enter and switch to the 3rd console by pressing Alt+F3. Now switch back to the 2nd console by pressing Alt+F2. Type sleep 5; echo tty > /dev/tty, press Enter and switch to the 3rd console.
You can see that tty is the console where process starts, and tty0 is a always current console.
A:
-
/dev/consoleis a virtual set of devices which can be set as a parameter at boot time. It might be redirected to a serial device or a virtual console and by default points to/dev/tty0. When multipleconsole=options are passed to the kernel, the console output will go to more than one device. -
/dev/tty0is the current virtual console -
/dev/tty[1-x]is one of the virtual consoles you switch to with control-alt-F1 and so on. -
/dev/ttyis the console used by the process querying it. Unlike the other devices, you do not need root privileges to write to it. Note also that processes like the ones launched bycronand similar batch processes have no usable/dev/tty, as they aren't associated with any. These processes have a?in theTTYcolumn ofps -efoutput.
Linux控制台详解
本文详细解释了Linux系统中/dev/console、/dev/tty及/dev/tty0的区别及其用途。/dev/console通常指向当前虚拟控制台/dev/tty0,除非在启动时被重定向到串行设备。/dev/tty0代表当前虚拟控制台,而/dev/tty则表示使用它的进程所处的控制台。
4925

被折叠的 条评论
为什么被折叠?



