Using Screen

As applied mathematicians, we often must run long numerical simulations. However, we don't always want to stay at our desk babysitting the code in case it fails. The solution is GNU screen.

Suppose we have two machines: laptop and caampc. Our goal is to start a simulation in Matlab on caampc and then access it from laptop at home, eating dinner.

First, in the office, open a new terminal, and run screen.

caampc $ screen
After running this command, the terminal appears to have restarted -- the screen has been cleared, and the command screen no longer appears; screen is now running. It has spawned a new terminal inside your old terminal that is persistent. If you close the terminal window, screen will still be running. More significantly, this terminal can be accessed again. Now that we're in screen lets fire up Matlab and run some code. GUI displays are not preserved by screen, so we need to run Matlab from the command line.
caampc $ matlab -nodesktop -nosplash
Once in Matlab, run the desired code.
>> really_long_numerics
Optionally, before you leave, detach the session, dropping back to your original terminal by pressing control-a and then control-d. The command control-a prefixes every screen command; control-d stands for detach.

Now, it's time to go home and enjoy a tasty dinner. On the computer you have with you, laptop, SSH into caampc.

laptop $ ssh
Once logged into caampc, start up screen again. This time, we need to tell screen to join the already running version. We do so by running
caampc $ screen -r
If you get an error like
There is a screen on: 10936.ttys005.baldr (Attached) There is no screen to be resumed.
you did not detach your already running session. To solve this, simply tell screen to force the detachment and move the terminal session to your current terminal using
caampc $ screen -rd
If everything is successful, you should be returned to the running session of Matlab. Any progress should be visible in the screen session. To quit screen, exit Matlab, and then kill the terminal session
caampc $ exit

For more information on screen, see the manual or a tutorial.

Duncan Hall 2108

curriculum vitae

PDF as of November 2011




TeX Install

related projects

CAAM335 Lab

Beaded string data

External Links

Taraborelli's beautiful LaTeX

Music for Programming