Physics Computing

Screen

The command "screen" can be used to open a terminal that can be 'detached' into the background, and reattached it at a later point. Anything running in that terminal will continue to run in the background, just as if you had left it open.

A typical situation where this would be useful would be when a piece of code takes a long time to run, overnight maybe, but you'd still like to be able to run it.

Running screen and Detaching

To begin, open a terminal (console) and type "screen". This will launch screen, and screen will bring up another prompt for you to use (all you'll actually see is the console clearing). Then you can run the job as normal, or do any other console task. When you're ready to detach, or put the console in the background, type Ctrl-A, then press d (lowercase). The console should return to its state before you launched screen, with a message that screen has detached. Any programs that were running are still running, the console acts as if it were still there.

Re-attaching a screen session

To re-attach the screen, the command is "screen -r". If you have more than one screen detached, it will print a list, and you'll have to run "screen -r [screen number]". You can re-attach the screen from a different terminal, or even a different computer by using ssh into your workstation.

Exiting a screen session

To exit from screen, type "exit" from within the screen at the prompt. You should get a message that screen is terminating.

How to tell if your current terminal is inside screen

Sometimes it isn't easy to tell if you're currently running from within screen or not. To tell, look at the title of your terminal. Usually screen prepends its name to let you know you're in a screen. If not, you can type Ctrl-A, and then ?. Ctrl-A is screen's magic keystroke. Normally, anything you type goes to the program you run within screen, but Ctrl-A is the escape sequence, and it will send the next key you press as a command to screen. For example, d is detach. ? brings up a reference of all possible commands (but will only work within screen, hence it's a good indicator if it's currently running).

Screen has a large number of options and features, but the basics are what I find most useful. You can use Ctrl-A ? to get a quick reference to the commands.

Important note for realm machines

One more note. On realm machines, access to unity home directories is controlled by tokens. Typically, tokens are issued when you first login, and last for around 12 hours or so. If you run something for longer than that, you may find that access to your unity home directory has been cut off, causing any programs needing that to fail.
You can view your tokens and when they expire with the "tokens" command.
You can renew your tokens and increase their lifetime with the "kreset -l" command. The -l lets you specify the lifetime, you can set it to a maximum of 21 hours. If you're going to be running something overnight, I'd recommend running "kreset -l" first, although if the job isn't using any afs resources, it should run fine.