【CentOS 7筆記52】,screen虛擬終端#

shallow丿ovegit


screen工具bash

  • 爲了避免讓一個任務意外終端
  • nohup command &
  • screen是一個虛擬終端
  • yum install -y screen
  • screen直接回車就進入了虛擬終端
  • ctral a組合鍵再按d退出虛擬終端,但不是結束
  • screen -ls查看虛擬終端列表
  • screen -r id 進入指定的終端
  • screen -S aming
  • screen -r aming

執行腳本,時間長,腳本會輸出,不能中斷工具

[root@localhost ~]# yum install -y screen
Loaded plugins: fastestmirror
base                                                                        | 3.6 kB  00:00:00     
epel/x86_64/metalink                                                        | 7.9 kB  00:00:00     
extras                                                                      | 3.4 kB  00:00:00     
updates                                                                     | 3.4 kB  00:00:00     
(1/2): extras/7/x86_64/primary_db                                           | 130 kB  00:00:00     
(2/2): updates/7/x86_64/primary_db                                          | 4.5 MB  00:00:07     
Loading mirror speeds from cached hostfile
 * epel: mirrors.sohu.com
Resolving Dependencies
--> Running transaction check
---> Package screen.x86_64 0:4.1.0-0.23.20120314git3c2946.el7_2 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===================================================================================================
 Package         Arch            Version                                       Repository     Size
===================================================================================================
Installing:
 screen          x86_64          4.1.0-0.23.20120314git3c2946.el7_2            base          552 k

Transaction Summary
===================================================================================================
Install  1 Package

Total download size: 552 k
Installed size: 914 k
Downloading packages:
screen-4.1.0-0.23.20120314git3c2946.el7_2.x86_64.rpm                        | 552 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : screen-4.1.0-0.23.20120314git3c2946.el7_2.x86_64                                1/1 
  Verifying  : screen-4.1.0-0.23.20120314git3c2946.el7_2.x86_64                                1/1 

Installed:
  screen.x86_64 0:4.1.0-0.23.20120314git3c2946.el7_2                                               

Complete!

進入虛擬終端code

[root@localhost ~]# screen
[root@localhost ~]#
[root@localhost ~]# w
 09:49:41 up  5:26,  2 users,  load average: 0.08, 0.06, 0.06
USER     TTY        LOGIN@   IDLE   JCPU   PCPU WHAT
root     tty1      04:24    1:43m  0.07s  0.07s -bash
root     pts/0     09:48    5.00s  0.01s  0.00s w

使用w看不出任何變化ci

[root@localhost ~]# vmstat 1
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 1  0      0 1513996    692 197840    0    0     5     1   12   15  0  0 100  0  0
 0  0      0 1513956    692 197872    0    0     0     0   31   35  0  0 100  0  0
 0  0      0 1513956    692 197872    0    0     0     0   19   21  0  0 100  0  0
 0  0      0 1513956    692 197872    0    0     0     9   36   53  0  0 100  0  0
 0  0      0 1513956    692 197872    0    0     0     0   40   61  0  0 100  0  0
 0  0      0 1513956    692 197872    0    0     0     0   41   65  0  0 100  0  0
 0  0      0 1513956    692 197872    0    0     0     0   41   63  0  0 100  0  0
.
.
.

(ctrl+A)+Dit

[root@localhost ~]# screen
[detached from 4497.pts-1.localhost]

screen -lsio

[root@localhost ~]# screen -ls
There is a screen on:
	4497.pts-1.localhost	(Detached)
1 Socket in /var/run/screen/S-root.

返回screen -r 4497ast

[root@localhost ~]# screen -r 4497
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 1  0      0 1513996    692 197840    0    0     5     1   12   15  0  0 100  0  0
 0  0      0 1513956    692 197872    0    0     0     0   31   35  0  0 100  0  0
 0  0      0 1513956    692 197872    0    0     0     0   19   21  0  0 100  0  0
 0  0      0 1513956    692 197872    0    0     0     9   36   53  0  0 100  0  0
 0  0      0 1513956    692 197872    0    0     0     0   40   61  0  0 100  0  0
 0  0      0 1513956    692 197872    0    0     0     0   41   65  0  0 100  0  0
 0  0      0 1513956    692 197872    0    0     0     0   41   63  0  0 100  0  0
.
.
.
^C
[root@localhost ~]# exit
[root@localhost ~]# screen -ls
No Sockets found in /var/run/screen/S-root.
[root@localhost ~]# screen
[detached from 4558.pts-1.localhost]
[root@localhost ~]# screen
[detached from 4576.pts-1.localhost]
[root@localhost ~]# screen
[detached from 4594.pts-1.localhost]
[root@localhost ~]# screen -ls
There are screens on:
	4594.pts-1.localhost	(Detached)
	4576.pts-1.localhost	(Detached)
	4558.pts-1.localhost	(Detached)
3 Sockets in /var/run/screen/S-root.

screen -S "name"test

[root@localhost ~]# screen -S "test_screen"
[detached from 4613.test_screen]
[root@localhost ~]# screen -ls
There are screens on:
	4613.test_screen	(Detached)
	4594.pts-1.localhost	(Detached)
	4576.pts-1.localhost	(Detached)
	4558.pts-1.localhost	(Detached)
4 Sockets in /var/run/screen/S-root.
相關文章
相關標籤/搜索