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 

Using Terminal Screen Command

This is a simple one. For some reason, every time I use the screen command in terminal, I forget the commands.

There are probably lots of cool reasons to use screen but I use it to run a script over a longish period. The advantage of screen is I can start the script in the screen instance and detach from it. I can close my laptop and return later to my terminal, open my screen and check the progress of the script. Also, you can run multiple instances of a script as each screen has its own process.

So the basic commands I use and tend to forget are… Continue reading “Using Terminal Screen Command”