这篇笔记来自于stackoverflow
的一篇帖子,答案如下:
From the documentation(http://www.kernel.org/doc/Documentation/devices.txt):
/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.
早些时候,/dev/console
是系统管理员控制台,而TTYs
则代表用户连接服务器的串行设备。而现在,/dev/console
和/dev/tty0
均指当前的显示设备,并且通常情况下是一样的。你可以修改/dev/console
所关联的设备。举个例子,在grub.conf
中加入console=ttyS0
。则现在,/dev/tty0
所关联的是显示器,而dev/console
则关联/dev/ttyS0
。
/dev/tty
是当前进程控制的tty
设备,而tty0
则是当前的控制台。当你在一个终端执行“sleep 5; echo tty0 > /dev/tty0
”命令后,切换到其它终端,则tty0
会在你切换后的终端显示。而执行“sleep 5; echo tty > /dev/tty
”命令后,无论切换到那个终端,tty
始终会在输入命令的终端显示。