如何在Linux中停止屏幕进程?

发布于 2024-11-14 22:47:52 字数 141 浏览 1 评论 0原文

我正在远程服务器上运行脚本。我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

£冰雨忧蓝° 2024-11-21 22:47:52

CTRL+a 然后“k”将终止屏幕会话。

CTRL+a and then 'k' will kill a screen session.

困倦 2024-11-21 22:47:52

有几种“屏幕”方法可以从命令行(非交互式)终止特定的屏幕会话。

1) 发送“退出”命令:

screen -X -S "sessionname" quit

2) 向运行脚本的屏幕会话发送 Ctrl-C:

screen -X -S "sessionname" stuff "^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:

screen -X -S "sessionname" quit

2) send a Ctrl-C to a screen session running a script:

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.

江南月 2024-11-21 22:47:52

我用它来退出由有缺陷的命令创建的数百个错误的屏幕会话:

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 number 1, 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 in for loop is not clear, for example, the one generated by sub-command in $() expansion.

GRAY°灰色天空 2024-11-21 22:47:52

以前的答案在 winputty 终端和亚马逊 ssh 服务器连接上对我不起作用..但这一个确实有效:

screen -S yourscreentitlehere -X stuff 

参考文献:

\003'

参考文献:

previous answers didn't work for me on a winputty terminal and amazon ssh server connection.. but this one does work:

screen -S yourscreentitlehere -X stuff 

references:

\003'

references:

初心未许 2024-11-21 22:47:52

我正在使用腻子,似乎我已经在屏幕中并且无法打开和关闭。每次我“退出”时,我都会关闭腻子窗口。这是终端打印

>>screen -r

    21063.unlimited (11/08/20 15:45:19)     (Attached)
    24054.cure6     (11/08/20 09:46:13)     (Attached)

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

    21063.unlimited (11/08/20 15:45:19)     (Attached)
    24054.cure6     (11/08/20 09:46:13)     (Attached)

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文