Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.
screen -list  shows 

There are screens on:
    9531.pts-0.ubuntu   (03/02/2011 12:43:34 PM)    (Detached)
    2101.pts-0.ubuntu   (03/02/2011 12:39:17 PM)    (Attached)
    2219.pts-0.ubuntu   (03/02/2011 11:20:56 AM)    (Attached)
3 Sockets in /var/run/screen/S-bond.

but when I type

screen -r 2101.pts-0.ubuntu
There is a screen on:
    2101.pts-0.ubuntu   (03/02/2011 12:39:16 PM)    (Attached)
There is no screen to be resumed matching 2101.pts-0.ubuntu.

Here I can not get back the the screen 2101.pts-0.ubuntu and infact I get exited. Where as if I do

screen -r 9531.pts-0.ubuntu
[detached from 9531.pts-0.ubuntu]

then above you can see I went inside that session and came out and I can do it again and again.But with other sessions same is not the case? SO what mistake am I doing?

share|improve this question

2 Answers 2

up vote 5 down vote accepted

As you can see from screen -list, that screen session is currently attached. You cannot attach to it from somewhere else without detaching it first. You can do this by adding the -d option, like screen -d -r 2101.pts-0.ubuntu. There is more information in the GNU Screen manual. Here is an excerpt:

-r [pid.tty.host]
-r sessionowner/[pid.tty.host]
resumes a detached screen session. No other options (except combinations with -d/-D) may be specified, though an optional prefix of [pid.]tty.host may be needed to distinguish between multiple detached screen sessions. The second form is used to connect to another user's screen session which runs in multiuser mode. This indicates that screen should look for sessions in another user's directory. This requires setuid-root

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

-x Attach to a not detached screen session. (Multi display mode).

Note: It is always a good idea to check the status of your sessions by means of "screen -list".

share|improve this answer
    
You can also use -x –  Steven Mar 2 '11 at 22:27
    
thanks a lot for this information. –  Registered User Mar 3 '11 at 11:17

Call the doctor!

screen -dr 2101.pts-0.ubuntu
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.