91

Somehow I managed to close a screen window without screen 'noticing' it, so the session is still flagged as attached. This prevents me from re-attaching to this session. What can I do?

me@iupr-serv8:~$ screen -r
There are several suitable screens on:
    25028.pts-19.XXX-serv8  (01/05/2012 07:15:34 PM)    (Attached)
    24658.pts-19.XXX-serv8  (01/05/2012 07:11:38 PM)    (Detached)
    24509.pts-19.XXX-serv8  (01/05/2012 07:10:00 PM)    (Detached)
    18676.pts-5.XXX-serv8   (01/02/2012 06:55:33 PM)    (Attached)
Type "screen [-d] -r [pid.]tty.host" to resume one of them.
me@XXX-serv8:~$ screen -r 25028
There is a screen on:
    25028.pts-19.XXX-serv8  (01/05/2012 07:15:33 PM)    (Attached)
There is no screen to be resumed matching 25028.

[update]

In the end I found out, that the session was not lost, but the ID of the first session is 0. The second session than has the ID 1.

4 Answers 4

122

Try detaching it first with screen -d. If that doesn't work, you can try, in increasing order of emphasis,

   -d|-D [pid.tty.host]
        does  not  start screen, but detaches the elsewhere running screen session. It has the
        same effect as typing "C-a d" from screen's controlling terminal. -D is the equivalent
        to  the  power  detach key.  If no session can be detached, this option is ignored. In
        combination with the -r/-R option more powerful effects can be achieved:

   -d -r   Reattach a session and if necessary detach it first.

   -d -R   Reattach a session and if necessary detach or even create it first.

   -d -RR  Reattach a session and if necessary detach or create it. Use the first  session  if
           more than one session is available.

   -D -r   Reattach a session. If necessary detach and logout remotely first.

   -D -R   Attach  here and now. In detail this means: If a session is running, then reattach.
           If necessary detach and logout remotely first.  If it was not running create it and
           notify the user. This is the author's favorite.

   -D -RR  Attach here and now. Whatever that means, just do it.
2
  • 11
    the -d -r options together will force attach that session. Jan 9, 2012 at 15:00
  • I always use screen -x so I can attach from multiple locations at once. Of course, if you accidentally close a window, it seems like -d -r is better just to keep things tidy.
    – mpontillo
    Jan 10, 2012 at 1:29
8
screen -r '1234.somescreensession'

There is a screen on:

1234.somescreensession (Attached)

There is no screen to be resumed matching 1234.somescreensession.

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

screen -D -r '1234.somescreensession'
5

I experienced the same problem after my ssh connection closed unexpectedly with the message Write Failed: broken pipe while I had a screen session attached. However, I could not get my screen session to reattach using any of the commands above. Note that I use the following version:

~> screen --version
Screen version 4.00.03 (FAU) 23-Oct-06

Apparently, there was still an instance of sshd running, which kept me from detaching and reattaching the session. After identifying the PID of the appropriate instance of sshd and killing it I was able to reattach with screen -r.


Just for information: You will definitely find more than one sshd demon, one will correspond to your current login and another belonging to the stale screen session (indeed, there could be multiple other sshds running belonging to multiple other screens).

1
  • 1
    I had the same issue good call
    – dianovich
    Aug 16, 2015 at 12:18
4

Some times the multiple screens are running in the background.

They can be resumed by:

screen -r [pid]

To get the screen, first run screen -R, then you will see all the running PIDs of screen, after that resume by screen -r [pid].

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .