如何在linux中停止屏幕进程?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6301840/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to stop a screen process in linux?
提问by David
I am running a script on a remote server. I ran the script in screen
, however I need to stop it before it completes since I need to update the script. I can easily detach from screen
, however, is there a way to kill a screen
process?
我在远程服务器上运行脚本。我在 中运行了脚本screen
,但是我需要在它完成之前停止它,因为我需要更新脚本。我可以轻松地与 分离screen
,但是,有没有办法终止screen
进程?
采纳答案by Nik
CTRL+a and then 'k' will kill a screen session.
CTRL+a 然后 'k' 将终止屏幕会话。
回答by troyfolger
There are a couple of 'screen' ways to kill a specific screen session from the command line (non-interactively).
有几种“屏幕”方法可以从命令行(非交互式)终止特定的屏幕会话。
1) send a 'quit' command:
1)发送“退出”命令:
screen -X -S "sessionname" quit
2) send a Ctrl-C to a screen session running a script:
2) 将 Ctrl-C 发送到运行脚本的屏幕会话:
screen -X -S "sessionname" stuff "^C"
In both cases, you would need to use 'screen -ls' to find the session name of the screen session you want to kill ... if there is only one screen session running, you won't need to specify the -S "sessionname" parameter.
在这两种情况下,您都需要使用 'screen -ls' 来查找要终止的 screen 会话的会话名称...如果只有一个 screen 会话正在运行,则不需要指定 -S “会话名称”参数。
回答by biocyberman
I used this to quit hundreds of erroneous screen sessions created by a buggy command:
我用它来退出由错误命令创建的数百个错误的屏幕会话:
for s in $(screen -ls|grep -o -P "1\d+.tty"); do screen -X -S $s quit; done;
for s in $(screen -ls|grep -o -P "1\d+.tty"); do screen -X -S $s quit; done;
where: the grep -o -P "1\d+.tty"
is the command to get session names with Perl-like name regex "1\d+.tty"
which captures all sessions start with number 1
, has some other numbers (\d
) and end with .tty
其中:grep -o -P "1\d+.tty"
是使用类似 Perl 的名称正则表达式获取会话名称的命令,"1\d+.tty"
它捕获所有以 number 开头的会话1
,还有一些其他数字 ( \d
) 并以.tty
Warning: You should test with this command first to see you get the exact list of sessions you want before apply the above command. This is to avoid quitting unwanted sessions:
警告:在应用上述命令之前,您应该首先使用此命令进行测试,以查看您获得所需会话的确切列表。这是为了避免退出不需要的会话:
for s in $(screen -ls|grep -o -P "1\d+.tty"); do echo $s; done;
for s in $(screen -ls|grep -o -P "1\d+.tty"); do echo $s; done;
I always to this echo
test whenever the list in for
loop is not clear, for example, the one generated by sub-command in $()
expansion.
echo
每当for
循环中的列表不清楚时,我总是进行此测试,例如,$()
扩展中的子命令生成的列表。
回答by mgear
previous answers didn't work for me on a winputty terminal and amazon ssh server connection.. but this one does work:
以前的答案在 winputty 终端和亚马逊 ssh 服务器连接上对我不起作用..但这个确实有效:
screen -S yourscreentitlehere -X stuff $'##代码##3'
references:
参考: