Topic: screen: Keep Your Processes Running Despite A Dropped Connection

I guess you all know this: you are connected to your server with SSH and in the middle of compiling some software or doing some other task which takes lots of time, and suddenly your connection drops for some reason, and you lose your labour. This can be very annoying, but fortunately there is a small utility called screen which lets you reattach to a previous session so that you can finish your task. This short tutorial shows how to use screen for just this purpose.

Using screen

With screen you can create one or more sessions in your current SSH terminal. Just run screen
beacon% screen
to start it. This creates a screen session or window (although you don't see it as such) in your current SSH terminal:

Press Space or Return to get to the command prompt:
 
Looks like your normal SSH terminal, doesn't it?
Now I'm going to describe the most important screen commands that you need to control screen. These commands begin with CTRL a to distinguish them from normal shell commands.

Last edited by _beastie_ (2009-04-02 18:40:42)

Re: screen: Keep Your Processes Running Despite A Dropped Connection

Nice little intro.  Used screen for several years, but have since moved all my BSD systems over to use tmux.  If it ever get packaged for Debian/Ubuntu, I'll be moving those over as well.

For those who prefer BSD-licensed code, there's also tmux.  Works the same as screen, but the default command key is CTRL+b instead of CTRL+a, so it doesn't mess up things line start-of-line (CTRL+a) or end-of-line (CTRL-e).  There's also a nice status bar in tmux, that lists all the "windows" you have open, and what command is running in them.

Re: screen: Keep Your Processes Running Despite A Dropped Connection

Thanks. I'll try tmux as well wink. Never heard about it earlier, because was completely satisfied with screen and never thought about its alternatives.

Re: screen: Keep Your Processes Running Despite A Dropped Connection

thanks for the tmux suggestion. i hate how you have to install screen from source sometimes (as opposed to packages).

now i can go with tmux!

--

while i wait to post this---

The following errors need to be corrected before the message can be posted:

    * At least 60 seconds have to pass between posts. Please wait a little while and try posting again.

translation: please wait a minute while we waste your time.

or: there is a maximum of 10080 posts per user per week.

Last edited by lucas (2009-04-05 08:16:45)

Re: screen: Keep Your Processes Running Despite A Dropped Connection

Screen really does have a problem with ctrl-a, especially when you're using Minicom. Bleh! The author of tmux really did us a favor by using ctrl-b as the escape/control key sequence.

I haven't found a way to change the default sequence on screen or on Minicom to keep them from colliding.

Re: screen: Keep Your Processes Running Despite A Dropped Connection

Been using tmux instead of screen for the last few weeks, love it!
Thanks for the tip!

Trust me, I know what I'm doing.

Re: screen: Keep Your Processes Running Despite A Dropped Connection

There is a way to change the control keys in screen, although I've never looked through the man page to see how.  smile  It's probably something simple in a .screenrc, but that's yet another thing to configure on each server.  big_smile

Re: screen: Keep Your Processes Running Despite A Dropped Connection

tmux pkg ftw

Re: screen: Keep Your Processes Running Despite A Dropped Connection

For those that use Ubuntu, it seems they've included a screen-profiles package that make screen a lot more useful/usable.  Ars Technica gives a nice overview.  Shouldn't be too hard to extract the contents of the package to use the profiles on other OSes.

Last edited by phoenix (2009-04-28 18:19:04)