分类: LINUX
3、控制终端(/dev/tty) 如果当前进程有控制终端(Controlling Terminal)的话,那么/dev/tty就是当前进程的控制终端的设备特殊文件。可以使用命令”ps –ax”来查看进程与哪个控制终端相连。对于你登录的shell,/dev/tty就是你使用的终端,设备号是(5,0)。使用命令”tty”可以查看它 具体对应哪个实际终端设备。/dev/tty有些类似于到实际所使用终端设备的一个联接。
4、控制台终端(/dev/ttyn, /dev/console) 在Linux 系统中,计算机显示器通常被称为控制台终端 (Console)。它仿真了类型为Linux的一种终端(TERM=Linux),并且有一些设备特殊文件与之相关联:tty0、tty1、tty2 等。当你在控制台上登录时,使用的是tty1。使用Alt+[F1—F6]组合键时,我们就可以切换到tty2、tty3等上面去。tty1–tty6等 称为 虚拟终端,而tty0则是当前所使用虚拟终端的一个别名,系统所产生的信息会发送到该终端上(这时也叫控制台终端)。因此不管当前正在使用哪个虚拟终端, 系统信息都会发送到控制台终端上。
/dev/console即控制台,是与操作系统交互的设备,系统将一些信息直接输出到控制台上。目前只有在单用户模式下,才允许用户登录控制台。
tty:
如果一个进程有控制终端的话,/dev/tty 就是它的控制终端,这个东西不是固定的,不同的程序打开这个 设备文件可能指向的终端不同。
#echo "test" > /dev/tty
test
tty0:
tty1 –tty6等称为虚拟终端,而tty0则是当前所使用虚拟终端的一个别名,系统所产生的信息会发送到
该终端上。因此不管当前正在使用哪个虚拟终端,系统信息都会发送到控制台终端上。
#echo "test" > /dev/tty0
test
(注意:好像要在文本模式下才可以)
/dev/tty主要是针对进程来说的,而/dev/tty0是针对整个系统来说的
就是说同是/dev/tty文件,对不同的进程来说,其具体指向是不同的。
但不管对那个进程来说/dev/tty0指向的都是当前的虚拟终端.
38.6 The Controlling TerminalIn article 38.5 , we pointed out that the ps command needs special options ( -x for BSD and -e for System V) to list processes without a controlling terminal. But just what is a controlling terminal? Just what it sounds like: the terminal from which the process was started. In the ps listing, this is usually given as a tty , or terminal id. That ps entry usually corresponds to a serial port, or a pty ( 41.8 ) . A pty or "pseudo-terminal" is a construct that makes a window or network login ( 1.33 ) look to the operating system just like a terminal. In the ps listing, a tty might appear as How does a process "lose" its controlling terminal? Easy. Some processes, such as system "daemons" ( 1.14 ) never had one - they were started by system scripts that weren't started from any terminal, or they disconnected themselves from their controlling terminals. But it's also possible that you started a process running in the background, logged out, and logged back later or on another terminal to find it still running without a controlling terminal. The tty command can be used to report which "terminal" you're currently connected to. For example: % Running tty without a controlling terminal gives the message |
Explaining The Terminal Welcome Screen3
Terminal

Hey
A couple of days ago I received an email asking me to explain Terminal’s welcome screen. For new users this can be quite confusing and many wonder what each parts mean. This post is going to be a quick introduction on what each line means and way it is there. I will also have a couple of links to posts explaining each part in more detail. If you have any questions please leave a comment below.
When you start Terminal you should see something like this.
or
Last login: Sat Jan 16 18:34:23 on ttys000
Welcome James
dyn240089:~ James$
The first line:
Last login: Sat Jan 16 18:34:23 on ttys000
is all about when you last logged into your Terminal, this can be semi useful if you use remote login or similar to see when the last log in was. Most of the time I ignore it since I can never remember when I last used Terminal.
The final part ttys000
is the Terminal you have logged into. It comes from when computers were a lot slower and older. You can find more information over on this Computer Terminal wiki page. The ttys, starts at zero and increases as you open more Terminal windows.
The second line:
Welcome James
is you message of the day. I can’t remember the original how ever you can change it by following thispost. You could add something witty, or reduce the amount of space on screen by deleting any of the text.
The final line:
dyn240089:~ James$
is made up of two parts. The first is your computer. This can be named from System Preferences > Sharing, text box at the top of the page. Most of the time this can be changed by you. However sometimes the network you connect to (as is the case with mine) will change it. It can vary sometimes local host is displayed. Keep an eye on it to make your you are using the right Terminal, especially if you have ssh’d or are using remote log in.
The final part, after the colon, is the short name of the current user. This should be who you are logged in with. If you are using ssh, this will change.
There isn’t a lot too the three lines in Terminal, however for new people this may be quite difficult to understand. If you have any questions please leave a comment. Alternatively you can find more information in some books. I recommend Mac OS X Unix Toolbox and The Mac OS X Command Linefrom Amazon.