Gnu-Screen

殺死多個具有相同名稱的 GNU 螢幕會話

  • November 11, 2018

有時我的腳本會出錯,並且會創建多個同名的螢幕會話。有沒有辦法在一個命令中用這個名字殺死所有這些?

Rx:/scripts# screen -S haydoz-script -X quit
There are several suitable screens on:
       13372.haydoz-script     (09/10/11 07:44:05)     (Detached)
       12287.haydoz-script     (09/10/11 07:30:45)     (Detached)
       12230.haydoz-script     (09/10/11 07:17:42)     (Detached)
       7824.haydoz-script      (09/09/11 11:42:26)     (Detached)
       7764.haydoz-script      (09/09/11 11:35:40)     (Detached)
       15753.haydoz-script     (09/04/11 15:00:27)     (Detached)
       15744.haydoz-script     (09/04/11 15:00:26)     (Detached)

除了這些我不想殺死的螢幕之外,還有其他螢幕正在執行。

如果沒有其他screen會話正在執行,您可以使用“硬”方式,僅kill使用killall screen.

如果你想變得更好,你可以遍歷你的螢幕會話列表並一個接一個地殺死它們:

# screen -S foo && screen -S foo
[detached]
[detached]
# screen -ls
There are screens on:                                                                                                                                                                                      
       8350.foo        (Detached)                                                                                                                                                                         
       8292.foo        (Detached)                                                                                                                                                                         
2 Sockets in /tmp/screens/S-joschi.                                                                                                                                                                        

# This is the interesting line. Just replace "foo" with the name of your session(s)
# for session in $(screen -ls | grep -o '[0-9]*\.foo'); do screen -S "${session}" -X quit; done
# screen -ls
No Sockets found in /tmp/screens/S-joschi.

引用自:https://unix.stackexchange.com/questions/20435