- 浏览: 4729798 次
- 性别:
- 来自: 上海
文章分类
最新评论
-
bzhao:
你也应该可以这样:(not tested)./rbtunnel ...
在Bash脚本中怎么关闭文件描述符? -
bzhao:
如果有A进程原代码情况下,通过如下调用,把他的子进程继承关闭则 ...
在Bash脚本中怎么关闭文件描述符? -
Master-Gao:
楼主咋没分析下源码呢?
我使用过的Linux命令之dirname - 截取给定路径的目录部分 -
jiedushi:
tail -F 就可以吧
Linux下实时跟踪log4j日志文件的bash脚本 - 增强了tail -f的功能 -
java_is_new:
新手学习了,就是不明白为一个网卡配多个ip有什么用
我使用过的Linux命令之ifconfig - 网络配置命令
我使用过的Linux命令之screen - 虚拟终端屏幕管理器
本文链接:http://codingstandards.iteye.com/blog/781839 (转载请注明出处)
用途说明
经常在维护Linux服务器的时候发现,由于网络连接突然断开,正在执行的程序会非正常结束。好不容易运行了很长时间的程序,就这么挂了,痛心啊!当然你也可以改用后台运行,但有时候就是想看着它执行,为啥?怕出问题啊,而且有些程序不适合后台执行。这一切,在你知道有个screen命令之后,就会Over了!!!
screen命令就是一个这样的虚拟终端程序,你运行它之后,它的表现形式就是一个shell,你可以在它上面运行自己想运行的命令,尤其是那些耗时比较长的命令,如果不幸网络掉线,也没有关系,你可以重新连上去,发现程序还在那儿欢快的跑着呢,真是爽极了~!而且更强大的是,它还可以多人协作,适合于几个人共同解决问题,也可用于Linux教学。
但不是每个Linux系统在安装完之后有screen这个命令,你有可能很失望的发现,执行结果是这样的。
[root@qzt196 ~]# screen
-bash: screen: command not found
不过不用着急,找一下安装光盘,把它挂上去,然后去找screen-*.rpm,安装一下就可以了,如下所示:
[root@qzt196 ~]# mount /dev/cdrom
[root@qzt196 ~]# cd /mnt/cdrom
[root@qzt196 cdrom]# find . -name "screen-*rpm"
./Server/screen-4.0.3-1.el5.i386.rpm
[root@qzt196 cdrom]# rpm -ivh ./enterprise/Server/screen-4.0.3-1.el5.i386.rpm
warning: ./Server/screen-4.0.3-1.el5.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
Preparing... ########################################### [100%]
1:screen ########################################### [100%]
[root@qzt196 cdrom]# rpm -q screen
screen-4.0.3-1.el5
[root@qzt196 cdrom]# cd
[root@qzt196 ~]# screen
当前屏幕被清除,在顶上显示。这下就可以轻松使用screen命令了。
[root@qzt196 ~]#
常用参数
-x 连接到某个已经存在的screen上。如果没有,报错;只有一个,直接连接上;有多个,显示列表。
-S <sessionname> 创建名为sessionname的screen。
-x <sessionname> 连接到名为sessionname的screen。
Ctrl+a d 暂时离开screen。
exit 退出screen。
使用示例
示例一
[root@qzt196 ~]# screen
进入screen,屏幕清除了。
[root@qzt196 ~]# top
top - 02:42:24 up 11:39, 2 users, load average: 0.00, 0.00, 0.00
Tasks: 211 total, 1 running, 210 sleeping, 0 stopped, 0 zombie
Cpu(s): 0.0%us, 0.0%sy, 0.0%ni,100.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 14420992k total
,
713096k used, 13707896k free, 135132k buffers <=== 今天才发现这台机器有多余14G的内存,强大。
Swap: 2031608k total, 0k used, 2031608k free, 267244k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
29446 root 15 0 9008 2736 2188 S 0 0.0 0:00.23 sshd
29528 root 15 0 6116 1160 696 S 0 0.0 0:00.04 screen
29549 root 15 0 2316 1068 784 R 0 0.0 0:00.47 top
1 root 15 0 2056 636 544 S 0 0.0 0:00.67 init
2 root RT 0 0 0 0 S 0 0.0 0:00.04 migration/0
3 root 34 19 0 0 0 S 0 0.0 0:00.02 ksoftirqd/0
4 root RT 0 0 0 0 S 0 0.0 0:00.00 watchdog/0
5 root RT 0 0 0 0 S 0 0.0 0:00.07 migration/1
6 root 34 19 0 0 0 S 0 0.0 0:00.00 ksoftirqd/1
7 root RT 0 0 0 0 S 0 0.0 0:00.00 watchdog/1
8 root RT 0 0 0 0 S 0 0.0 0:00.04 migration/2
9 root 35 19 0 0 0 S 0 0.0 0:00.00 ksoftirqd/2
10 root RT 0 0 0 0 S 0 0.0 0:00.00 watchdog/2
省略更多输出
Ctrl+a d <=== 注:此处是先按Ctrl+a,然后按d。
[detached]
[root@qzt196 ~]#
换一个终端登录。
Last login: Sun May 16 02:29:20 2010 from 222.70.144.138
[root@qzt196 ~]# screen -x <=== 你会发现运行之后会出现top运行的全屏界面。
top - 02:42:39 up 11:39, 3 users, load average: 0.00, 0.00, 0.00
Tasks: 210 total, 1 running, 209 sleeping, 0 stopped, 0 zombie
Cpu(s): 0.0%us, 0.0%sy, 0.0%ni,100.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 14420992k total, 712972k used, 13708020k free, 135156k buffers
Swap: 2031608k total, 0k used, 2031608k free, 267244k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
29549 root 15 0 2316 1068 784 R 0 0.0 0:00.52 top
1 root 15 0 2056 636 544 S 0 0.0 0:00.67 init
2 root RT 0 0 0 0 S 0 0.0 0:00.04 migration/0
3 root 34 19 0 0 0 S 0 0.0 0:00.02 ksoftirqd/0
4 root RT 0 0 0 0 S 0 0.0 0:00.00 watchdog/0
5 root RT 0 0 0 0 S 0 0.0 0:00.07 migration/1
6 root 34 19 0 0 0 S 0 0.0 0:00.00 ksoftirqd/1
7 root RT 0 0 0 0 S 0 0.0 0:00.00 watchdog/1
8 root RT 0 0 0 0 S 0 0.0 0:00.04 migration/2
9 root 35 19 0 0 0 S 0 0.0 0:00.00 ksoftirqd/2
10 root RT 0 0 0 0 S 0 0.0 0:00.00 watchdog/2
省略更多输出
Ctrl+a d
[detached]
[root@qzt196 ~]#
示例二 网络断线测试
先screen,然后运行top,然后强行把远程连接断开,注意此处不需要先按Ctrl+a d,直接叉掉窗口就行了。
然后重新登录,看看top还在不在。
Last login: Sun May 16 02:40:12 2010 from 222.70.144.138
[root@qzt196 ~]# screen -x
top - 02:52:58 up 11:49, 2 users, load average: 0.09, 0.02, 0.01
Tasks: 209 total, 1 running, 208 sleeping, 0 stopped, 0 zombie
Cpu(s): 0.0%us, 0.0%sy, 0.0%ni,100.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 14420992k total, 714212k used, 13706780k free, 136008k buffers
Swap: 2031608k total, 0k used, 2031608k free, 267244k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
29549 root 15 0 2316 1068 784 R 0 0.0 0:02.66 top
1 root 15 0 2056 636 544 S 0 0.0 0:00.67 init
2 root RT 0 0 0 0 S 0 0.0 0:00.04 migration/0
3 root 34 19 0 0 0 S 0 0.0 0:00.02 ksoftirqd/0
4 root RT 0 0 0 0 S 0 0.0 0:00.00 watchdog/0
5 root RT 0 0 0 0 S 0 0.0 0:00.07 migration/1
6 root 34 19 0 0 0 S 0 0.0 0:00.00 ksoftirqd/1
7 root RT 0 0 0 0 S 0 0.0 0:00.00 watchdog/1
8 root RT 0 0 0 0 S 0 0.0 0:00.04 migration/2
9 root 35 19 0 0 0 S 0 0.0 0:00.00 ksoftirqd/2
10 root RT 0 0 0 0 S 0 0.0 0:00.00 watchdog/2
省略更多输出
果然还在。
q
[root@qzt196 ~]# exit
exit
[screen is terminating]
screen虚拟终端彻底退出了。
[root@qzt196 ~]# screen -x
There is no screen to be attached.
[root@qzt196 ~]#
示例三 多人同时编辑文件
从一个远程连接上执行screen命令,蓝色字体为本终端输入的内容。
Last login: Sun May 16 02:52:51 2010 from 222.70.144.138
[root@qzt196 ~]# screen vi 1.txt
Hello
World
~
在完成后面那屏幕的输入后,按
:wq
退出vi。
"1.txt" [New] 2L, 12C written
[screen is terminating]
[root@qzt196 ~]#
从另一终端上登录,连接到前面的screen上。发现vi界面,而且可以编辑。
Last login: Sun May 16 02:59:58 2010 from 222.70.144.138
[root@qzt196 ~]# screen -x
Hello
World
切换到前面那屏幕,你会发现那个屏幕上也会出现折行。
~
"1.txt" [New] 2L, 12C written
[screen is terminating]
[root@qzt196 ~]#
示例四 指定名字
创建一个名为helpme的screen。
[root@qzt196 ~]# screen -S helpme
[root@qzt196 ~]# vi 1.txt
Hello
World
~
"1.txt" 2L, 12C
另外登录一个终端,连接到名为helpme的screen上。
[root@qzt196 ~]# screen -x helpme
Hello
World
~
"1.txt" 2L, 12C
问题思考
1. 为什么关掉窗口/断开连接会使得正在运行的程序死掉?
2. screen有哪些快捷键?
3. 怎样显示当前有哪些screen?
相关资料
【1】IBM linux 技巧:使用 screen 管理你的远程会话
【2】ZDNet 服务器频道 使用Screen创建虚拟终端避免Linux远程断线
发表评论
-
在Linux用tar归档压缩文件时忽略某些文件和目录
2013-02-01 10:19 16913在Linux下,常用tar对文 ... -
使用nmap扫描服务器端口的一次操作
2012-11-01 17:00 15069使用nmap扫描服务器端口的一次操作 本文来自:http ... -
我使用过的Linux命令之wget - ooo
2011-09-14 13:10 0我使用过的Linux命令之wg ... -
推荐一篇学习Vim使用的好文:酷壳 - 简明 Vim 练级攻略
2011-09-09 12:53 9078简明 Vim 练级攻略 http://coolshell.c ... -
推荐一篇学习Vim使用的好文:酷壳 - 简明 Vim 练级攻略
2011-09-09 12:49 1简明 Vim 练级攻略 http://coolshell.c ... -
我使用过的Linux命令之:(冒号) - 啥也不做(除了……)
2011-08-29 13:18 11967我使用过的Linux命令之: ... -
我使用过的Linux命令之date - 显示、修改系统日期时间
2011-08-25 09:21 41895我使用过的Linux命令之da ... -
我使用过的Linux命令之declare - 声明shell变量(不知道没关系、知道了就更好的内建命令)
2011-08-16 09:22 21730我使用过的Linux命令之declare - 声明shell变 ... -
我使用过的Linux命令之alias - 设置命令的别名,让 Linux 命令更简练
2011-08-11 09:31 28698我使用过的Linux命令之alias - 设置命令的别名,让 ... -
我使用过的Linux命令之ar - 创建静态库.a文件
2011-08-08 10:40 51801我使用过的Linux命令之ar - 创建静态库.a文件 本 ... -
我使用过的Linux命令之crontab - 设置例行任务(类似于Windows中的任务计划)
2011-08-04 22:26 9685我使用过的Linux命令之crontab - 设置例行任务(类 ... -
我使用过的Linux命令之chmod - 改变文件/目录的访问权限
2011-08-03 21:33 10634我使用过的Linux命令之chmod - 改变文件/目录的访问 ... -
我使用过的Linux命令之export - 设置或显示环境变量
2011-08-02 19:55 25356我使用过的Linux命令之export - 设置或显示环境变量 ... -
我使用过的Linux命令之wc - 统计文件行数、单词数或字节数
2011-07-26 10:50 28918我使用过的Linux命令之wc - 统计文件行数、单词数或字节 ... -
我使用过的Linux命令之groupdel - 删除群组
2011-07-22 22:13 9611我使用过的Linux命令之gr ... -
我使用过的Linux命令之ifconfig - 网络配置命令
2011-07-21 20:43 60355我使用过的Linux命令之ifconfig - 网络配置命令 ... -
我使用过的Linux命令之ll - 列出文件/目录的详细信息
2011-07-20 21:22 7093我使用过的Linux命令之ll ... -
我使用过的Linux命令之mkdir - 创建目录
2011-07-20 20:58 13598我使用过的Linux命令之mkdir - 创建目录 本文链 ... -
我使用过的Linux命令之perror - 解释错误代码
2011-07-18 20:29 24947我使用过的Linux命令之perror - 解释错误代码 ... -
我使用过的Linux命令之ping - 测试与目标主机的连通性
2011-07-16 10:46 26202我使用过的Linux命令之ping - 测试与目标主机的连通性 ...
相关推荐
big-screen-vue-master vue 大屏
screen-4.1.0-0.25.20120314git3c2946.el7.x86_64 rpm linux 64,一款后台管理软件
llinux screen 命令详细解释 llinux screen 命令详细解释
Linux后台运行软件-screen-rpm-直接安装,方便部署维护,祖传级软件
rd-screen-recorder-8
本文介绍了linux下screen命令的使用方法。
screen-4.0-程序员运维必备-后台运行应用-linux-64-32位.rar 1. 资源内容:后台运行应用screen 可方便管理后台应用,告别 -d ,告别nohup 2. 使用目标:运维,后台运行应用,linux 后台运行 3. 应用场景:部署 和 ...
Screen-Vehicle-Detection-using-Tensorflow-API-master.zipScreen-Vehicle-Detection-using-Tensorflow-API-master.zipScreen-Vehicle-Detection-using-Tensorflow-API-master.zipScreen-Vehicle-Detection-using-...
录屏软件rd-screen-recorder-100.exe
full-page-screen-capture-chrome-extension, 在 Google Chrome 中,点击全页面屏幕截图 整页屏幕截图一个简单的Google Chrome 扩展,它获取完整网页的屏幕截图。 我尝试的每个扩展都不能在 Chrome OSX Lion 上的22...
Dell-On-Screen-Display-Application,戴尔屏幕显示驱动
新升级完美解决鼠标问题,解决支持不同分辨率,不同DPI的主屏幕,副屏幕,增加GDI模式下的主副屏采集。同时支持32位和64位。screen-capture-recorder.dll是一款很不错的录屏dshow filter。也可以叫虚拟摄像头,他...
Android-From-Screen-To-Screen-Acticity-Example 两个activity相互跳转
官方离线安装包,亲测可用。使用rpm -ivh [rpm完整包名] 进行安装
Linux命令大全搜索工具,内容包含Linux命令手册、详解、学习、搜集。 Linux命令分类 这里存放Linux 命令大全并不全,你可以通过linux-command来搜索,它是把 command 目录里面搜集的...
Black Screen 是终端世界中的一个IDE。 严格地说,它既是终端仿真器,也是基于Electron的交互式shell。
:house: :sparkles:浏览器支持 react-screen-wake-lock使用原生的Screen Wake Lock API,并非所有浏览器都支持。 安装npm i react-screen-wake-lock# oryarn add react-screen-wake-lock用法 import { useWakeLock ...
linux 下ffmpeg 录屏源码,Linux 下基于x11grab的录屏程序
Vue网络屏幕截图· web端自定义截屏插件(Vue3版),运行视频:插件,本插件仅支持Vue3,如需在其他平台使用请移步: 效果图如下:插件安装yarn add vue-web-screen-shot# ornpm install vue-web-screen-shot --save...
名称:BombBomb Video - Webcam & Screen ---------------------------------------- 版本:5.5.11 作者:https://bombbomb.com/ 分类:生产工具 ---------------------------------------- 概述:使用 BombBomb ...