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
screen -ls
But this doesn't work. Anything wrong? What's the correct way?
"kill" will only kill one screen window. To "kill" the complete session, use quit.
$ screen -X -S [session # you want to kill] quit
For dead sessions use: $ screen -wipe
exit works but needs to be typed into each screen that was opened. quit does not even workscreen -X quit on any terminal terminates all active sessionsYou can kill a detached session which is not responding within the screen session by doing the following.
Type screen -list to identify the detached screen session.
~$ screen -list
There are screens on:
20751.Melvin_Peter_V42 (Detached)
Note: 20751.Melvin_Peter_V42 is your session id.
Get attached to the detached screen session
screen -r 20751.Melvin_Peter_V42
Once connected to the session press Ctrl + A then type :quit
quit and :quit lead to command not found on my remote Linux server (perhaps differences between versions of the OS or screen are to blame)exit also worksList 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
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
screen -S and not screen -r?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:
cd /tmp/uscreens/S-xxx
ls
26727.pts-0.devxxx
rm 26727.pts-0.devxxx
ls
The uscreens directory will not have the 26727.pts-0.devxxx file in it anymore. Now to make sure just type this:
screen -ls
and you should get:
No Sockets found in /tmp/uscreens/S-xxx.
ps aux | grep screen found the pid and I issued a kill to remove it. Depending on what you had running in your screen, you may have temp files and locks to clean up as well.screen -wipe
Should clean all dead screen sessions.
add this to your ~/.bashrc:
alias cleanscreen="screen -ls | tail -n +2 | head -n -2 | awk '{print $1}'| xargs -I{} screen -S {} -X quit"
Then use cleanscreen to clean all screen session.
screen -ls | grep Detached | cut -d. -f1 | awk '{print $1}' | xargs killscreen -ls | tail +2 | head -2 | awk '{print $1}'| xargs -I{} screen -S {} -X quitFor me a simple
exit
works. This is from within the screen session.
:quitTo kill all detached screen sessions, include this function in your .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
== 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.
screen -S sessionname -p 0 -X quit