/dev/tty 与 /dev/pts

 打开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

原文地址:https://www.cnblogs.com/zengkefu/p/5558840.html