如何在Linux中停止屏幕进程?
我正在远程服务器上运行脚本。我在 screen
中运行了脚本,但是我需要在它完成之前停止它,因为我需要更新脚本。我可以轻松地与 screen
分离,但是,有没有办法杀死 screen
进程?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
CTRL+a 然后“k”将终止屏幕会话。
CTRL+a and then 'k' will kill a screen session.
有几种“屏幕”方法可以从命令行(非交互式)终止特定的屏幕会话。
1) 发送“退出”命令:
2) 向运行脚本的屏幕会话发送 Ctrl-C:
在这两种情况下,您都需要使用“screen -ls”来查找您想要的屏幕会话的会话名称Kill ...如果只有一个屏幕会话正在运行,则无需指定 -S“sessionname”参数。
There are a couple of 'screen' ways to kill a specific screen session from the command line (non-interactively).
1) send a 'quit' command:
2) send a Ctrl-C to a screen session running a script:
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.
我用它来退出由有缺陷的命令创建的数百个错误的屏幕会话:
for s in $(screen -ls|grep -o -P "1\d+.tty");执行 screen -X -S $s 退出; done;
其中:
grep -o -P "1\d+.tty"
是使用类似 Perl 的名称正则表达式"1\d+.tty 获取会话名称的命令"
捕获以数字1
开头、有一些其他数字 (\d
) 并以.tty
结尾的所有会话警告:
在应用上述命令之前,您应该首先使用此命令进行测试,以查看是否获得了所需的确切会话列表。这是为了避免退出不需要的会话:
for s in $(screen -ls|grep -o -P "1\d+.tty");做回显 $s; 每当
for 循环中的列表不清楚时,我总是进行此
echo
测试,例如,由中的子命令生成的列表$()
扩展。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;
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 number1
, has some other numbers (\d
) and end with.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;
I always to this
echo
test whenever the list infor
loop is not clear, for example, the one generated by sub-command in$()
expansion.以前的答案在 winputty 终端和亚马逊 ssh 服务器连接上对我不起作用..但这一个确实有效:
参考文献:
previous answers didn't work for me on a winputty terminal and amazon ssh server connection.. but this one does work:
references:
我正在使用腻子,似乎我已经在屏幕中并且无法打开和关闭。每次我“退出”时,我都会关闭腻子窗口。这是终端打印
>>screen -r
There is no screen to be returned.
和
screen -S 21063.unlimited -X stuff $'\003'
不执行任何操作。
我发现就像下面一行一样简单,它可以完美地工作
screen -x 21063.unlimited
它将我带回屏幕,然后从那里“退出”工作。
注意是小写的
-x
I am using putty, and it seems I am already in the screen and couldn't open and close. Every time I do "exit", I just close the putty window. Here is the termimal print
>>screen -r
There is no screen to be resumed.
and
screen -S 21063.unlimited -X stuff $'\003'
does not do anything.
I found that as simple as the following line works perfect
screen -x 21063.unlimited
it sends me back into the screen and from there "exit" works.
Note that it is lower-case
-x