How to access attached screen after connection dropped

Here’s the situation, you are using bash’s Screen command because you don’t want your flakey internet connection to affect whatever you are working on, and sure enough, the connection drops. Sometimes, when you try to re-attach to this screen session you are told that the screen session is still attached…

~$ screen -r '1234.somescreensession'
There is a screen on:
1234.somescreensession (Attached)
There is no screen to be resumed matching 1234.somescreensession.

How annoying.

UPDATE:
Here is a simple way to take back that screen session.

screen -D -r '1234.somescreensession'

Kudos to Donncha O’Caoimh

Here is a way a longer way to remove the process that is attached to that screen session, so you can reattach to it and continue with whatever you were doing.

  • figure out which tty is holding on to the screen session by typing into terminal
    ps -ef | grep screen | grep tty
  • result of this should be something like
    testdev 5760 5688 0 12:31 ttyp1 00:00:00 screen -r 1234.somescreensession
  • in this case the tty is 5688, use this to find the login bash that is associated with that tty
    ps -ef | grep bash | grep 5688
  • result of this should be something like
    testdev 5688 5687 0 12:28 ttyp1 00:00:00 -bash
  • kill process
    kill -9 5687

Now you should be free to re-attach to this screen session.

Kudos to David Mackintosh 

19 thoughts on “How to access attached screen after connection dropped

    1. when you start a screen session with a name ‘screen -S yourprogramname’ you can reattach your detached screen by call it with ‘screen -r yourp’. So you don’t have to type any numbers..

  1. wow.. i sepnd like 15-20 min to figue this out how to do it, then finally searched this forum.. and able to reattached it :)..
    thanks a lot!

  2. if you have a single screen session running and the connection dropped, typing “screen -x” will attach you directly to that single screen session

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s