74

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.

Bo A
  • 3,144
  • 2
  • 33
  • 49
Slowcoder
  • 2,060
  • 3
  • 16
  • 21

11 Answers11

127
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

Desta Haileselassie Hagos
  • 23,140
  • 7
  • 48
  • 53
22

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.

vefthym
  • 7,422
  • 6
  • 32
  • 58
naveen nani
  • 247
  • 2
  • 3
7

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

TheWiz
  • 101
  • 1
  • 3
5

From Screen User's Manual ;

screen -d -r "screenName"

Reattach a session and if necessary detach it first

Cugomastik
  • 911
  • 13
  • 22
3

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
seralouk
  • 30,938
  • 9
  • 118
  • 133
1

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

Community
  • 1
  • 1
andreskwan
  • 1,152
  • 1
  • 13
  • 13
1

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
0

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>

Hutch
  • 10,392
  • 1
  • 22
  • 18
  • Yes, that was the first command I tried. but it didn't respond. I tried to open as root user but the screen was not even detected for root user account. – Slowcoder Feb 11 '13 at 04:58
0

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]

Siddhant
  • 41
  • 5
0

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

MillerMedia
  • 3,651
  • 17
  • 71
  • 150
-2

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.

HuyLe
  • 28
  • 3
  • This is not very helpful: it's just part of the man page and a cheat sheet wich the OP has certainly read. – matiasg Jul 21 '15 at 11:10