4

I'm new to screen and I'm trying to figure out how to detach from a session and reattach later. So far I've tried:

$screen
C-a z (within screen to detach)
$screen -r

So far so good but when I C-a z to detach again, I see 2 screen processes running:

$ps
  PID TTY           TIME CMD
33145 ttys000    0:00.06 -bash
33176 ttys000    0:00.01 screen
33407 ttys000    0:00.01 screen -r

If I detach and reattach again I get another screen process, etc...

So, how can I reattach to the screen session without spawning a new process?

Thanks!

spinlock
  • 183
  • 5

2 Answers2

6

Try to detach within a screen:

ctrl a d

to reattach:

screen -rd (detaches the screen first if was attached)

There is also:

screen -x (attaches the screen again, so you can watch the screen with two sessions)

Lucas Kauffman
  • 16,880
  • 9
  • 58
  • 93
  • 2
    To elaborate: `^A z` (or `^A ^Z`) ***suspends*** screen (the equivalent of `^Z` to most processes). `^A d` (or `^A ^D`)is the Detach command. To get back the screen session you suspended you need to use `fg` or other OS job control commands. – voretaq7 Mar 02 '12 at 19:37
3

C-a z suspends your screen process. If your shell is bash, you can see the stopped process by running jobs and resume it with fg. Detaching is a different concept.

To detach from a session, use C-a d. You will still see the screen process in your process list, and you can list it by running screen -ls. Resume with screen -r, but read the man page about the different ways to resume a running screen session.

Congratulations on learning about screen! It's an amazing tool.

bonsaiviking
  • 4,420
  • 17
  • 26
  • Thanks! screen really is amazing. I can't believe I'm just learning about it now. I ran across it while trying to find a way to do remote pair programming and now it's as ingrained in my development process as git. – spinlock Mar 07 '12 at 16:38