我从某个地方了解到,分离的屏幕可能会被

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

可以从中获取[您要终止的会话#]

screen -ls

但这行不通。有什么问题吗?正确的方法是什么?


当前回答

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

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

要运行它,请调用killd

其他回答

您只需转到屏幕会话所在的位置并运行:

 screen -ls

这导致

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

只需删除它:

cd/tmp/uscreens/S-xxxls26727.pts-0.devxxxrm26727.pts-0.devxxxls

uscreens目录中不再包含26727.pts-0.devxxx文件。现在,确保只需键入以下内容:

屏幕-ls

你应该得到:

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

将此添加到~/.bashrc:

alias cleanscreen="screen -ls | tail -n +2 | head -n -2 | awk '{print $1}'| xargs -I{} screen -S {} -X quit"

然后使用cleanscreen清理所有屏幕会话。

screen -wipe

应清除所有死屏会话。

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

//Creation:
screen -S some_name proc
// Kill detached session
screen -S some_name -X quit
== 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.