Linux 多窗口管理 screen

本文介绍了Linux下的screen工具,用于在SSH连接时管理多个终端窗口。通过screen,可以轻松创建、查看、切换和退出多个会话,即使终端断开连接,进程也能在后台继续运行。安装screen后,使用快捷键进行操作,如Ctrl+a + w查看状态,Ctrl+a + d暂时退出,screen -ls列出所有会话,screen -r恢复会话,以及Ctrl+a: quit关闭会话。screen是管理和控制后台进程的强大工具。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

使用背景

用ssh连接到Linux服务器,启动tornado,当前session则一直被占据,笨办法是再开一个terminal,不过这样很乱。终端机器关机后很难再管理之前的会话。遂,借助工具 screen,Screen是一个全屏的窗口管理工具,使一个实体终端管控多个进程,典型应用是交互式shells。
官网 http://www.gnu.org/software/screen/

Ubuntu安装

sudo apte-get install screen

基础使用

新建一屏

screen -S screenName001

此时会新开一个bash窗口

查看当前状态

Ctrl+a + w

显示出这个样子 0*$ bash ,多个screen时,* 标记为当前屏幕。

暂时退出当前屏

ctrl+a +d
令该屏为detached状态,进程仍在后台运行。此时退回普通窗口。

在普通窗口查看screen状态

screen -ls
会列出在运行的各个screen

进入其中一个

screen -r screenName001
也可以用进程号进入,或者『进程号.screenName001』

杀死当前screen

ctrl+a:quit
退出当前屏,一并杀死该屏中所有进程。

screen options一览

Options:
-4            Resolve hostnames only to IPv4 addresses.
-6            Resolve hostnames only to IPv6 addresses.
-a            Force all capabilities into each window's termcap.
-A -[r|R]     Adapt all windows to the new display width & height.
-c file       Read configuration file instead of '.screenrc'.
-d (-r)       Detach the elsewhere running screen (and reattach here).
-dmS name     Start as daemon: Screen session in detached mode.
-D (-r)       Detach and logout remote (and reattach here).
-D -RR        Do whatever is needed to get a screen session.
-e xy         Change command characters.
-f            Flow control on, -fn = off, -fa = auto.
-h lines      Set the size of the scrollback history buffer.
-i            Interrupt output sooner when flow control is on.
-l            Login mode on (update /var/run/utmp), -ln = off.
-ls [match]   or -list. Do nothing, just list our SockDir [on possible matches].
-L            Turn on output logging.
-m            ignore $STY variable, do create a new screen session.
-O            Choose optimal output rather than exact vt100 emulation.
-p window     Preselect the named window if it exists.
-q            Quiet startup. Exits with non-zero return code if unsuccessful.
-r [session]  Reattach to a detached screen process.
-R            Reattach if possible, otherwise start a new session.
-s shell      Shell to execute rather than $SHELL.
-S sockname   Name this session <pid>.sockname instead of <pid>.<tty>.<host>.
-t title      Set title. (window's name).
-T term       Use term as $TERM for windows, rather than "screen".
-U            Tell screen to use UTF-8 encoding.
-v            Print "Screen version 4.01.00devel (GNU) 2-May-06".
-wipe [match] Do nothing, just clean up SockDir [on possible matches].
-x            Attach to a not detached screen. (Multi display mode).
-X            Execute <cmd> as a screen command in the specified session.

参考
http://www.gnu.org/software/screen/
http://www.cnblogs.com/mchina/archive/2013/01/30/2880680.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值