Kill detached screen session

LinuxKillGnu Screen

Linux Problem Overview


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?

Linux Solutions


Solution 1 - Linux

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

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

For dead sessions use: $ screen -wipe

Solution 2 - Linux

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

  1. 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.

  2. Get attached to the detached screen session

    screen -r 20751.Melvin_Peter_V42

  3. Once connected to the session press Ctrl + A then type :quit

Solution 3 - Linux

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

Solution 4 - Linux

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

Solution 5 - Linux

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

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.

Solution 6 - Linux

screen -wipe

Should clean all dead screen sessions.

Solution 7 - Linux

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.

Solution 8 - Linux

For me a simple

exit

works. This is from within the screen session.

Solution 9 - Linux

To 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

Solution 10 - Linux

== 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.

Solution 11 - Linux

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

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

No need to bother with screen session id, etc.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionTimView Question on Stackoverflow
Solution 1 - LinuxinnaMView Answer on Stackoverflow
Solution 2 - LinuxMelvin PeterView Answer on Stackoverflow
Solution 3 - LinuxCollin ThomasView Answer on Stackoverflow
Solution 4 - LinuxHitman_99View Answer on Stackoverflow
Solution 5 - Linuxrc2012View Answer on Stackoverflow
Solution 6 - LinuxVishv JeetView Answer on Stackoverflow
Solution 7 - Linuxuser2115803View Answer on Stackoverflow
Solution 8 - LinuxNick DesaulniersView Answer on Stackoverflow
Solution 9 - LinuxRose PerroneView Answer on Stackoverflow
Solution 10 - LinuxduggiView Answer on Stackoverflow
Solution 11 - Linuxdat789View Answer on Stackoverflow