[linux] Kill Attached Screen in Linux

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.

This question is related to linux gnu-screen

The answer is


You could create a function to kill all existing sessions. take a look at 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


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.


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

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.


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]


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


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>


From Screen User's Manual ;

screen -d -r "screenName"

Reattach a session and if necessary detach it first


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


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