Sunday, February 24, 2008


Have you ever wondered, it you could shut down your machine and yet keep the remote sessions as it is. So if you have a process which takes 2-3 days to run and you cannot afford to shut down the machine. What do you try to do... Try to run the process in background. Or you are running a heavy process and after some time (cause you are in india), the net connection just snaps for 2 minutes. And lo your complete process has to happen again.

Well, the most frustrating is the point when your process is 99% over and it breaks along with the session.

"Screen" is something that could help you here. What is screen? Screen is described as a terminal multiplexer using which you can run any number of console based applications. The cool feature of screen is its ability to decouple the terminal emulator from the running programs. This means that you can use screen to keep programs running after you accidentally close the terminal emulator, or even after you log out, and later resume right where you were. It means that the idea of a "session" in which you are running a number of console programs is a free-floating entity that you can bind to any terminal anywhere.

Cool na. Ok, so how do we use it?

All you have got to remember is that the screen remains active until the machine on which it is running is still alive.

So, ssh to the remote machine and type "screen" on your console and you see - no change. You might see a splash page but then it looks like any other empty terminal. In reality, you are now inside a screen process and you can run any heavy process you want.

You can create new windows inside screen by pressing Ctrl+a+c. And then run another process in the window. You can use Ctrl+a+<space> to switch between the running windows inside screen.

So now, you have your processes running and you want to logout and shut down your computer and let the process run on the remote machine. Here is what you do.

Press Ctrl+a+d and you are detached from your screen. So your processes are still running inside the screen and you can logout and shut down your comp and maybe login again from home and check the status of the process. You dont believe me. I knew it...

So just do a Ctrl+a+r, and lo behold, you are back into your screen and you can switch between multiple windows and see the processes running. This should put your mind at rest.

You can get more information from and
GNU Screen: an introduction and beginner's tutorial

1 comment:

Anonymous said...

I love screen. If you work somewhere and have remote access using ssh (or have access to home from work for example) you can leave a screen running and ssh in, screen -r and you're back at work.

If anyone ever asks how we managed before rdesktop and PCAnywhere, screen is it! Also screen preserves the environment so any X11 graphical output will happen where the original screen was run. It also means you can run those annoying tools that mostly work from the command line but insist on throwing up a splash screen.

Great blog, I found it through searching for text indexing info, but there's lots more to read :)