screen命令

370阅读 0评论2015-10-23 sync_1521
分类:LINUX

刚刚才注意,默认情况下rhel6 是不安装screen命令的:

[html] view plaincopy在CODE上查看代码片派生到我的代码片
  1. [root@rhel63single yum.repos.d]# yum install screen  
  2. Loaded plugins: product-id, refresh-packagekit, security, subscription-manager  
  3. Updating certificate-based repositories.  
  4. Unable to read consumer identity  
  5. rhel-source                                                                                                                          | 4.0 kB     00:00 ...   
  6. rhel-source-beta                                                                                                                     | 4.0 kB     00:00 ...   
  7. Setting up Install Process  
  8. Resolving Dependencies  
  9. --> Running transaction check  
  10. ---> Package screen.x86_64 0:4.0.3-16.el6 will be installed  
  11. --> Finished Dependency Resolution  
  12.   
  13. Dependencies Resolved  
  14.   
  15. ============================================================================================================================================================  
  16.  Package                           Arch                              Version                                   Repository                              Size  
  17. ============================================================================================================================================================  
  18. Installing:  
  19.  screen                            x86_64                            4.0.3-16.el6                              rhel-source                            494 k  
  20.   
  21. Transaction Summary  
  22. ============================================================================================================================================================  
  23. Install       1 Package(s)  
  24.   
  25. Total download size: 494 k  
  26. Installed size: 795 k  
  27. Is this ok [y/N]: y  
  28. Downloading Packages:  
  29. Running rpm_check_debug  
  30. Running Transaction Test  
  31. Transaction Test Succeeded  
  32. Running Transaction  
  33.   Installing : screen-4.0.3-16.el6.x86_64                                                                                                                          1/1   
  34. Installed products updated.  
  35.   Verifying  : screen-4.0.3-16.el6.x86_64                                                                                                                          1/1   
  36.   
  37. Installed:  
  38.   screen.x86_64 0:4.0.3-16.el6                                                                                                                                           
  39.   
  40. Complete!  
  41. [root@rhel63single yum.repos.d]# which screen  
  42. /usr/bin/screen  
  43. [root@rhel63single yum.repos.d]#   


一、screen 的建立

[html] view plaincopy在CODE上查看代码片派生到我的代码片
  1. [root@rhel63single ~]# screen -ls  
  2. No Sockets found in /var/run/screen/S-root.  
  3.   
  4. [root@rhel63single ~]#   
  5. [root@rhel63single ~]#   
  6. [root@rhel63single ~]# screen -dmS lei1  
  7. [root@rhel63single ~]# screen -ls  
  8. There is a screen on:  
  9.         5786.lei1       (Detached)  
  10. 1 Socket in /var/run/screen/S-root.  
  11.   
  12. [root@rhel63single ~]#  
  13. 其中:5786是linux的ospid。lei1是会话的名称。  


二、screen 的进入

[html] view plaincopy在CODE上查看代码片派生到我的代码片
  1. [root@rhel63single ~]# screen -r lei1  


三、暂时退出某个screen 的session :先按ctrl ,再按小写的a,再按小写的d

 

[html] view plaincopy在CODE上查看代码片派生到我的代码片
  1. [root@rhel63single ~]#   
  2.   
  3.   
  4.               
  5. [detached]  
  6. [root@rhel63single ~]#   


四、若是本来就在该session中,再使用screen -r lei1命令时的提示:

[html] view plaincopy在CODE上查看代码片派生到我的代码片
  1. [root@rhel63single ~]# screen -r lei  或者用screen -r 5786  
  2. There is a screen on:  
  3.         5786.lei1       (Attached)  
  4. There is no screen to be resumed matching lei.  
  5. [root@rhel63single ~]#   

五、状态解释:

[html] view plaincopy在CODE上查看代码片派生到我的代码片
  1. [root@rhel63single ~]# screen -dmS lei2  
  2. [root@rhel63single ~]#   
  3. [root@rhel63single ~]#   
  4. [root@rhel63single ~]#   
  5. [root@rhel63single ~]# screen -ls  
  6. There are screens on:  
  7.         5850.lei2       (Detached)---->挂起状态,无终端在连接会话  
  8.         5786.lei1       (Attached)---->有终端在连接会话。  
  9. 2 Sockets in /var/run/screen/S-root.  
  10.   
  11. [root@rhel63single ~]#   

 

六、永久退出screen中的本session,该session将不存在了

[html] view plaincopy在CODE上查看代码片派生到我的代码片
  1. [root@rhel63single ~]# exit  
  2.                            exit  
  3.   
  4.   
  5.                           
  6. [screen is terminating]  
  7. [root@rhel63single ~]# screen -ls  
  8. There is a screen on:  
  9.         5850.lei2       (Detached)  
  10. 1 Socket in /var/run/screen/S-root.  
  11.   
  12.    


七、检查screen中的其他session的来源ip:

[html] view plaincopy在CODE上查看代码片派生到我的代码片
  1. [root@rhel63single ~]# who -a  
  2.            system boot  2015-03-19 12:36  
  3.            run-level 5  2015-03-19 12:36  
  4. LOGIN      tty2         2015-03-19 12:37              1979 id=2  
  5. LOGIN      tty4         2015-03-19 12:37              1983 id=4  
  6. LOGIN      tty3         2015-03-19 12:37              1981 id=3  
  7. LOGIN      tty5         2015-03-19 12:37              1985 id=5  
  8. LOGIN      tty6         2015-03-19 12:37              1987 id=6  
  9. root     + pts/0        2015-03-19 19:05 00:17        5306 (192.168.80.1)  
  10.            pts/1        2015-03-19 22:29              5787 id=/1    term=0 exit=0  
  11.            pts/2        2015-03-19 22:33              5810 id=ts/2  term=0 exit=0  
  12. root     + pts/3        2015-03-19 22:33   .          5830 (192.168.80.1)  
  13. root     + pts/4        2015-03-19 22:42 00:11        5851 (192.168.80.1:S.0)---->注意此处  
  14. [root@rhel63single ~]# screen -ls  
  15. There is a screen on:  
  16.         5850.lei2       (Attached)  
  17. 1 Socket in /var/run/screen/S-root.  
  18.   
  19. [root@rhel63single ~]# ps -ef | grep 5851---->注意此处  
  20. root      5851  5850  0 22:33 pts/4    00:00:00 /bin/bash  
  21. root      5974  5830  0 22:56 pts/3    00:00:00 grep 5851  
  22. [root@rhel63single ~]# ps -ef | grep 5850---->注意此处  
  23. root      5850     1  0 22:33 ?        00:00:00 SCREEN -dmS lei2 ---->注意此处  
  24. root      5851  5850  0 22:33 pts/4    00:00:00 /bin/bash ---->注意此处  
  25. root      5883  5810  0 22:42 pts/2    00:00:00 screen -r 5850  
  26. [root@rhel63single ~]#   

八、检查当前的提示符是否处于screen的session中:

[html] view plaincopy在CODE上查看代码片派生到我的代码片
  1. 按ctrl,再按a,再按t  
  2.   
  3. 此时,在左下角会显示:“22:45:06 Mar 19 rhel63single 0.00 0.00 0.00” 字样  
  4. 格式为:当前时间,日期,主机名,负载情况  


九、杀掉screen中的其他session

[html] view plaincopy在CODE上查看代码片派生到我的代码片
  1. [root@rhel63single ~]# kill -9 5850  
  2. [root@rhel63single ~]# screen -ls  
  3. There is a screen on:  
  4.         5850.lei2       (Dead ???)  
  5. Remove dead screens with 'screen -wipe'.  
  6. 1 Socket in /var/run/screen/S-root.  
  7.   
  8. [root@rhel63single ~]# screen -wipe  
  9. There is a screen on:  
  10.         5850.lei2       (Removed)  
  11. 1 socket wiped out.  
  12. No Sockets found in /var/run/screen/S-root.  
  13.   
  14. [root@rhel63single ~]# screen -ls  
  15. No Sockets found in /var/run/screen/S-root.  
  16.   
  17. [root@rhel63single ~]#   

 

然后,被杀掉的session 有提示:

[html] view plaincopy在CODE上查看代码片派生到我的代码片
  1. [root@rhel63single ~]#   
  2. Suddenly the Dungeon collapses!! - You die...  
  3. [root@rhel63single ~]#   


补充一种情况,当你没有进入screen会话里但是screen -ls 又显示你想连接的会话为Attached
这时就要用 screen -D -r 了
clouder@server2-47:~> screen -ls
There are screens on:
        7037.test      (Attached)
1 Sockets in /var/run/uscreens/S-clouder.

clouder@server2-47:~> screen -D -r test
这相当于强制把连进这个会话的另一个终端T掉,另外一个被T掉的终端显示如下:
clouder@server2-47:~> 
                                      
[remote power detached]
Connection to 172.16.2.47 closed.
chenbl@server10:~> 



上一篇:父进程和子进程的变量传递
下一篇:proc文件系统详解