Linux 杀死分离的屏幕会话

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1509677/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 17:45:03  来源:igfitidea点击:

Kill detached screen session

linuxkillgnu-screen

提问by Tim

I learned from somewhere a detached screen can be killed by

我从某个地方了解到一个分离的屏幕可以被杀死

screen -X -S [session # you want to kill] kill

where [session # you want to kill] can be gotten from

[session # you want to kill] 可以从哪里得到

screen -ls

But this doesn't work. Anything wrong? What's the correct way?

但这不起作用。哪里不对了?正确的方法是什么?

采纳答案by innaM

"kill" will only kill one screen window. To "kill" the complete session, use quit.

“kill”只会杀死一个屏幕窗口。要“杀死”整个会话,请使用quit.

Example

例子

$ screen -X -S [session # you want to kill] quit

For dead sessions use: $ screen -wipe

对于死会话使用: $ screen -wipe

回答by Melvin Peter

You can kill a detached session which is not responding within the screen session by doing the following.

您可以通过执行以下操作来终止在屏幕会话中没有响应的分离会话。

  1. Type screen -listto identify the detached screen session.

    ~$ screen -list  
        There are screens on:  
             20751.Melvin_Peter_V42  (Detached)  
    

    Note: 20751.Melvin_Peter_V42is your session id.

  2. Get attached to the detached screen session

    screen -r 20751.Melvin_Peter_V42
  3. Once connected to the session press Ctrl+ Athen type :quit

  1. 键入screen -list以标识分离的屏幕会话。

    ~$ screen -list  
        There are screens on:  
             20751.Melvin_Peter_V42  (Detached)  
    

    注意:20751.Melvin_Peter_V42是您的会话 ID。

  2. 附加到分离的屏幕会话

    screen -r 20751.Melvin_Peter_V42
  3. 连接到会话后,按Ctrl+A然后键入:quit

回答by duggi

== ISSUE THIS COMMAND
[xxx@devxxx ~]$ screen -ls


== SCREEN RESPONDS
There are screens on:
        23487.pts-0.devxxx      (Detached)
        26727.pts-0.devxxx      (Attached)
2 Sockets in /tmp/uscreens/S-xxx.


== NOW KILL THE ONE YOU DONT WANT
[xxx@devxxx ~]$ screen -X -S 23487.pts-0.devxxx kill


== WANT PROOF?
[xxx@devxxx ~]$ screen -ls
There is a screen on:
        26727.pts-0.devxxx      (Attached)
1 Socket in /tmp/uscreens/S-xxx.

回答by Hitman_99

It's easier to kill a session, when some meaningful name is given:

当给出一些有意义的名称时,终止会话会更容易:

//Creation:
screen -S some_name proc
// Kill detached session
screen -S some_name -X quit

回答by rc2012

You can just go to the place where the screen session is housed and run:

您可以直接转到屏幕会话所在的位置并运行:

 screen -ls

which results in

这导致

 There is a screen on:
         26727.pts-0.devxxx      (Attached)
 1 Socket in /tmp/uscreens/S-xxx. <------ this is where the session is.

And just remove it:

只需将其删除:

  1. cd /tmp/uscreens/S-xxx
  2. ls
  3. 26727.pts-0.devxxx
  4. rm 26727.pts-0.devxxx
  5. ls
  1. cd /tmp/uscreens/S-xxx
  2. ls
  3. 26727.pts-0.devxxx
  4. rm 26727.pts-0.devxxx
  5. ls

The uscreensdirectory will not have the 26727.pts-0.devxxxfile in it anymore. Now to make sure just type this:

uscreens目录中将不再包含该26727.pts-0.devxxx文件。现在确保只需输入:

screen -ls

screen -ls

and you should get:

你应该得到:

No Sockets found in /tmp/uscreens/S-xxx.

在 /tmp/uscreens/S-xxx 中找不到套接字。

回答by dat789

Alternatively, while in your screen session all you have to do is type exit

或者,在您的屏幕会话中,您所要做的就是输入exit

This will kill the shell session initiated by the screen, which effectively terminates the screen session you are on.

这将终止由屏幕启动的 shell 会话,从而有效地终止您所在的屏幕会话。

No need to bother with screen session id, etc.

无需担心屏幕会话 ID 等。

回答by Vishv Jeet

screen -wipe

Should clean all deadscreen sessions.

应该清理所有屏会话。

回答by nilloc

List screens:

列表屏幕:

screen -list

Output:

输出:

There is a screen on:
23536.pts-0.wdzee       (10/04/2012 08:40:45 AM)        (Detached)
1 Socket in /var/run/screen/S-root.

Kill screen session:

杀死屏幕会话:

screen -S 23536 -X quit

回答by Nick Desaulniers

For me a simple

对我来说一个简单的

exit

works. This is from within the screen session.

作品。这是来自 screen 会话中的。

回答by Rose Perrone

To kill alldetached screen sessions, include this function in your .bash_profile:

要终止所有分离的屏幕会话,请在您的 .bash_profile 中包含此函数:

killd () {
for session in $(screen -ls | grep -o '[0-9]\{5\}')
do
screen -S "${session}" -X quit;
done
}

to run it, call killd

运行它,调用 killd