Kill Attached Screen in Linux

LinuxGnu Screen

Linux Problem Overview


I created a screen "myscreen" in linux and it stopped responding abruptly. I closed the terminal and tried to reopen it. "screen -ls" shows that the screen is Attached. I tried the following commands but nothing responds.

screen -r myscreen
screen -D myscreen
screen -D -RR myscreen
screen -X -S myscreen quit

Any help to reattach to the screen or to kill the screen is very much appreciated.

Linux Solutions


Solution 1 - Linux

screen -X -S SCREENID kill

alternatively, you can use the following command

screen -S SCREENNAME -p 0 -X quit

You can view the list of the screen sessions by executing screen -ls

Solution 2 - Linux

Create screen from Terminal:

screen -S <screen_name>

To see list of screens:

<screen -ls> or <screen -list>

To go to particular screen:

<screen -x screen_name>

<screen -r screen_name>

Inside screen


To Terminate screen:

give ctrl+d screen will get terminated

To Detach screen:

 give <ctrl+ad>or <screen -d >screen will get detached

To reattach screen:

screen -x <screen_name> or screen -r <screen_name>

To kill a screen from Terminal:

<screen -X -S screen_name quit> 

or

<screen -X -S screen_name kill>

You can use screen_name or process_id to execute commands.

Solution 3 - Linux

This worked for me very well. Get the screen id via:

screen -r

or

screen -ls

then kill the screen: kill -9 <screenID> it now becomes a dead screen, then wipe it out with: screen -wipe

Solution 4 - Linux

From Screen User's Manual ;

screen -d -r "screenName"

Reattach a session and if necessary detach it first

Solution 5 - Linux

You could create a function to kill all existing sessions. take a look at https://stackoverflow.com/questions/14447131/kill-all-detached-screen-sessions

to list all active sessions use screen -r

when listed, select with your mouse the session you are interested in and paste it. like this

screen -r

Solution 6 - Linux

Suppose your screen id has a pattern. Then you can use the following code to kill all the attached screen at once.

result=$(screen -ls | grep 'pattern_of_screen_id' -o)
for i in $result; 
do      
    `screen -X -S $i quit`;
done

Solution 7 - Linux

To kill a detached screen use this from the terminal:

screen -X -S "SCEEN_NAME" quit

If you are attached, then use (from the terminal and inside the screen):

exit

Solution 8 - Linux

i usually don't name my screen instances, so this might not be useful, but did you try screen -r without the 'myscreen' part? usually for me, screen -r will show the PIDs of each screen then i can reattach with screen -d -r <PID>

Solution 9 - Linux

You can find the process id of the attached running screen. I found it same as the session id which you can get by command:
screen -ls
And you can use following command to kill that process:
kill [sessionId] or
sudo kill [sessionId]

Solution 10 - Linux

None of the screen commands were killing or reattaching the screen for me. Any screen command would just hang. I found another approach.

Each running screen has a file associated with it in:

/var/run/screen/S-{user_name}

The files in that folder will match the names of the screens when running the screen -list. If you delete the file, it kills the associated running screen (detached or attached).

Solution 11 - Linux

For result find: Click Here

Screen is a full-screen window manager that multiplexes a physical terminal between several processes, typically interactive shells. There is a scrollback history buffer for each virtual terminal and a copy-and-paste mechanism that allows the user to move text regions between windows.

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
QuestionSlowcoderView Question on Stackoverflow
Solution 1 - LinuxDesta Haileselassie HagosView Answer on Stackoverflow
Solution 2 - Linuxnaveen naniView Answer on Stackoverflow
Solution 3 - LinuxTheWizView Answer on Stackoverflow
Solution 4 - LinuxCugomastikView Answer on Stackoverflow
Solution 5 - LinuxandreskwanView Answer on Stackoverflow
Solution 6 - LinuxMd Kauser AhmmedView Answer on Stackoverflow
Solution 7 - LinuxseraloukView Answer on Stackoverflow
Solution 8 - LinuxHutchView Answer on Stackoverflow
Solution 9 - LinuxSiddhantView Answer on Stackoverflow
Solution 10 - LinuxMillerMediaView Answer on Stackoverflow
Solution 11 - LinuxHuyLeView Answer on Stackoverflow