Surviving with “screen”

How does a physicist survive in a world where computing resources are spread across the globe? In big ways, we as a community try to address this question every day. In small ways – at the level of a single physicist – there are little tips and tricks that can make survival possible.

One of my favorite tricks is to use a program called “screen”. Screen creates a “shell within a shell”, giving you a prompt when you run it on a Linux or UNIX machine. What’s happened is that the screen program spawns a shell within your login shell which can be detached at any time. Detaching the screen shell leaves any program running inside screen alone, freeing you to logout of the machine and come back hours later to check on your work. This is in contrast to what happens if you were to run from a normal shell and try to logout. Often, this ends the running programs, leaving you to have to start all over again!

This may sound confusing, so the best thing to do is just try it. For instance, start “screen” and then type “ping google.com” when you get a prompt. Now, detach screen by pressing “CTRL+a CTRL+d”. The terminal will change back to your login prompt. Now, logout of the machine and twiddle your thumbs for a few seconds. Then, log back in and type “screen -r” to reattach to the screen session. You’ll see that while you were busy logging out and in, ping just kept running uninterrupted.

Imagine the possibilities. You can start running a program that requires a few hours to run, detach and go home. Meanwhile, the program runs on the machine where you ran screen. Hours later, you can log back in (from home, from a cafe, anywhere!) and reattach to see how your program is doing.

There is extensive information on the web about screen. Of course, there is also the manpage! Enjoy!

Print Friendly, PDF & Email

Leave a Reply

Your email address will not be published. Required fields are marked *