Tools I use: screen

The [[|screen website]] introduces screen thus:

//Screen is a full-screen window manager that multiplexes a physical terminal between several processes, typically interactive shells.//

But I don’t think it does justice to the utility of screen. Let me try to simply the introduction a little bit and motivate the usefulness of screen with some examples.

Lets say you started some long running simulation in your lab (for instance, a shell script that calls your main routine with different parameters; then collects/collates the data and also plots it). Now you leave it running and come back home with the hope that when you come in next morning, everything would be done.

But if something goes wrong in between, how do you find out? One cheap way to do this is to use ”nohup” and redirect the output of the process to some log file, and inspect the log file from home. But this is not neat. Ideally, you want to be able to interact with the process as if it was running locally (keystrokes and everything).

More importantly, how do you recover from failures? Say your script gets hung somewhere, and it needs some input to proceed. How do you do it from home? You can of course use remote desktop solutions such as VNC, but they typically have high bandwidth requirements, and are almost unusable over slow networks (as are to be found at most homes. Yes, that includes DSL and cable).

Basically, screen lets you run multiple shells, and “detach” them. Later on, you can simply SSH to your machine, and “reattach” your screen session and have your console workspace restored just as it was. You can monitor and interact with your jobs as if they were running locally. In some sense then, screen is a poor man’s version of full fledged remote desktop protocols, since it basically does the same thing for consoles.

But screen can be used for a lot of other things as well. As the introduction says, screen is a window manager. What that means is that you can have multiple “windows” within a single screen (think of them as buffers in an editor, or just multiple shells that you can switch between). You can split up the screen to display multiple windows at once. This is very convinient if you are editing your script in one window and executing it in another while tailing a log file in a third window, for instance.

Another popular use for screen is for doing collaborative editing. Screen’s can be shared across mutliple users, and so multiple parties can communicate using a single screen. You can edit a report together with your project partners, or just keep an eye on what your friends are typing ;-).

Finally, screen is infinitely configurable. Do ”man screenrc” for details. Here is a basic configuration file to get you started, save it as ”~/.screenrc”:

# no annoying audible bell, please
vbell on

# detach on hangup
autodetach on

# don't display the copyright page
startup_message off

# caption
caption always "%w"

# hardstatus
hardstatus alwayslastline "%H %C%a %M %d, %Y Load: %l "


  1. Pingback: Tools I use: tmux

Leave a Reply