running long jobs

A good way to run a long job is to use a screen session. You can detach from sessions, and anything started in the session keeps running. You can also reattach at a later time (even after logging out and back in later) to monitor the progress of your job.

Except for a few strange cases, you should not need to put a sign up on a computer, telling others not to log you off!

Simply start a screen session by typing screen in a terminal window:


This will create a screen session, which will keep on running apart from your normal terminal session. You can now navigate the terminal as per normal and start a long job running in the screen session:

cd cs81/superProject/
python3 >> test1.out

Screen does not save as much of your terminal output as a normal session, so you probably want to redirect the output of your job to a file (as shown above).

To “detach” from a screen session, hit ctrl-a then press d. This will return you to wherever you were before typing the screen command. Hoorah! Your script is now running in the background and you can safely log off.

To “reattach” to a screen session to check on it’s progress or perform more commands, log onto the machine where the screen session was made and type screen -r:

screen -r

This will take you back into your screen session.

graphical output

“But wait!”, you say, “Our test has graphical output which cannot be suppressed!” We now have a way to deal with this, too. It is called Xvfb. This command creates a fake graphics display (X virtual frame buffer) which graphical output will be pushed to. This means that you will not be able to see your graphical output, but for long training and tests typically you want the numbers, not the actual visual.

So start up your screen session as before:


Then use the Xvfb command to create the fake display to display output 3. Don’t worry about it, just use 2 or 3:

Xvfb :3 &          

Now tell your screen session to push graphical output to the fake display

export DISPLAY=:3

You are ready to run!

python >> test2.out

Then Cntrl-a d to detach from screen and let ’er go!

Come back later…

screen -r

Test success?!

cat test2.out

End the Xvfb session

pkill Xvfb

End the screen session:


See also:

Back to SwatCS Help Docs