打開3個bash會話窗口
[root@server1 fd]# cd /proc/7489/fd
[root@server1 fd]# ll
總用量 0
lrwx------ 1 root root 64 6月 5 23:55 0 -> /dev/pts/2
lrwx------ 1 root root 64 6月 5 23:55 1 -> /dev/pts/2
lrwx------ 1 root root 64 6月 5 23:55 2 -> /dev/pts/2
lrwx------ 1 root root 64 6月 5 23:55 255 -> /dev/pts/2
[root@server1 fd]# cd /proc/7508/fd
[root@server1 fd]# ll
總用量 0
lrwx------ 1 root root 64 6月 5 23:55 0 -> /dev/pts/3
lrwx------ 1 root root 64 6月 5 23:55 1 -> /dev/pts/3
lrwx------ 1 root root 64 6月 5 23:55 2 -> /dev/pts/3
lrwx------ 1 root root 64 6月 5 23:55 255 -> /dev/pts/3
[root@server1 fd]# cd /proc/6734/fd
[root@server1 fd]# ll
總用量 0
lrwx------ 1 root root 64 6月 5 23:56 0 -> /dev/pts/0
lrwx------ 1 root root 64 6月 5 23:56 1 -> /dev/pts/0
lrwx------ 1 root root 64 6月 5 23:56 2 -> /dev/pts/0
lrwx------ 1 root root 64 6月 5 23:56 255 -> /dev/pts/0
[root@server1 fd]# cd /dev/pts
[root@server1 pts]# ll
總用量 0
crw--w---- 1 root tty 136, 0 6月 5 18:26 0
crw--w---- 1 root tty 136, 1 6月 5 23:57 1
crw--w---- 1 root tty 136, 2 6月 5 23:54 2
crw--w---- 1 root tty 136, 3 6月 5 23:55 3
c--------- 1 root root 5, 2 5月 16 16:23 ptmx
[root@server1 pts]# tty
/dev/pts/1
[root@server1 ~]# tty
/dev/pts/2
[root@server1 ~]# tty
/dev/pts/3
tty:命令
tty - print the file name of the terminal connected to standard input
創健6個可切換終端:
root 1019 1 0 May16 tty1 00:00:00 /sbin/mingetty /dev/tty1
root 1021 1 0 May16 tty2 00:00:00 /sbin/mingetty /dev/tty2
root 1023 1 0 May16 tty3 00:00:00 /sbin/mingetty /dev/tty3
root 1025 1 0 May16 tty4 00:00:00 /sbin/mingetty /dev/tty4
root 1027 1 0 May16 tty5 00:00:00 /sbin/mingetty /dev/tty5
root 1029 1 0 May16 tty6 00:00:00 /sbin/mingetty /dev/tty6
ALT +F[1-6]切換,
[root@localhost dev]# tty
/dev/pts/1
[root@localhost dev]# echo "0" > /dev/tty0
所有的tty[1-6]都顯示 0
1 當前控制終端(/dev/tty)
/dev/tty指的是當前所處的終端,輸出到此的內容只會顯示在當前工作的終端顯示器上;可以使用命令”ps –ax”來查看進程與哪個控制終端相連.對於你登錄的shell,
/dev/tty就是你使用的終端,設備號是(5,0).
使用命令”tty”可以查看自己具體對應哪個實際終端設備./dev/tty有些類似於到實際所使用終端設備的一個聯接
2./dev/pts
/dev/pts是遠程登陸(telnet,ssh等)后創建的控制台設備文件所在的目錄。由於可能有好幾千個用戶登陸,所以/dev/pts其實是動態生成的,不象其他設備文件是構建系統時就已經產生的硬盤節點.
3.控制台終端-系統控制台(/dev/console 和 /dev/tty*)
在Linux系統中,計算機顯示器通常被稱為控制台終端(Console).它仿真了類型為Linux的一種終端(TERM=Linux),並且有一些設備特殊文件與之相關聯:
tty0、tty1、tty2等.當你在控制台上登錄時,使用的是tty1.使用Alt+[F1—F6]組合鍵時,我們就可以切換到tty2、tty3等上面去.tty1–tty6等稱為虛擬終端,
而tty0則是當前所使用虛擬終端的一個別名,系統所產生的信息會發送到該終端上.因此不管當前正在使用哪個虛擬終端,系統信息都會發送到控制台終端上.
你可以登錄到不同的虛擬終端上去,因而可以讓系統同時有幾個不同的會話期存在.只有系統或超級用戶root可以向/dev/tty0進行寫操作.
root 4665 925 0 13:53 ? 00:00:00 sshd: root@pts/0
root 4667 4665 0 13:53 pts/0 00:00:00 -bash
root 4744 925 0 14:53 ? 00:00:00 sshd: root@pts/1
root 4746 4744 0 14:53 pts/1 00:00:00 -bash
root 4843 925 0 16:24 ? 00:00:00 sshd: root@pts/2
root 4845 4843 0 16:24 pts/2 00:00:00 -bash
root 4860 925 0 16:24 ? 00:00:00 sshd: root@pts/3
root 4862 4860 0 16:24 pts/3 00:00:00 -bash
root 4877 925 0 16:24 ? 00:00:00 sshd: root@pts/4
root 4879 4877 0 16:24 pts/4 00:00:00 -bash
root 4894 925 0 16:24 ? 00:00:00 sshd: root@pts/5
root 4896 4894 0 16:24 pts/5 00:00:00 -bash
root 4911 925 0 16:25 ? 00:00:00 sshd: root@pts/6
root 4913 4911 0 16:25 pts/6 00:00:00 -bash
root 4935 925 0 16:25 ? 00:00:00 sshd: root@pts/7
root 4937 4935 0 16:25 pts/7 00:00:00 -bash
root 4954 925 0 16:25 ? 00:00:00 sshd: root@pts/8
[root@server1 ~]# cd /dev/pts
[root@server1 pts]# ll
總用量 0
crw--w---- 1 root tty 136, 0 6月 4 16:25 0
crw--w---- 1 root tty 136, 1 6月 4 16:25 1
crw--w---- 1 root tty 136, 2 6月 4 16:25 2
crw--w---- 1 root tty 136, 3 6月 4 16:25 3
crw--w---- 1 root tty 136, 4 6月 4 16:25 4
crw--w---- 1 root tty 136, 5 6月 4 16:25 5
crw--w---- 1 root tty 136, 6 6月 4 16:25 6
crw--w---- 1 root tty 136, 7 6月 4 16:25 7
crw--w---- 1 root tty 136, 8 6月 4 16:28 8
c--------- 1 root root 5, 2 5月 16 16:23 ptmx
linux下看到的控制台(console)是由幾個設備完成的。分別是/dev/ttyN(其中tty0就是/dev/console,tty1,tty2就是不同的虛擬終端(virtual console))
通常使用熱鍵alt+Fn來在這些虛擬終端之間進行切換。所有的這些tty設備都是由linux/drivers/char /console.c和vt.c對應。
ALT+F7切回到GUI桌面
動態創健/dev/pts: root@server1 ~]# cd /dev/pts [root@server1 pts]# ll 總用量 0 crw--w---- 1 root tty 136, 0 6月 4 14:40 0 crw--w---- 1 root tty 136, 1 6月 4 13:52 1 c--------- 1 root root 5, 2 5月 16 16:23 ptmx [root@server1 pts]# ll 總用量 0 crw--w---- 1 root tty 136, 0 6月 4 14:40 0 c--------- 1 root root 5, 2 5月 16 16:23 ptmx
alt+[F1-F6] 進行切換 :當前切換為:alt+F5
[root@server1 dev]# cd pts [root@server1 pts]# ll 總用量 0 crw--w---- 1 root tty 136, 0 6月 4 15:58 0 crw--w---- 1 root tty 136, 1 6月 4 15:23 1 c--------- 1 root root 5, 2 5月 16 16:23 ptmx
pts+ptmx 實現tty登陸
init 1進入單用戶: tty為 /dev/console
