Tutorial: Running unattended jobs on P2C clusters using Screen

posted Jun 4, 2015, 12:46 AM by SRGICS UPLB   [ updated Oct 7, 2016, 12:34 AM ]
Some jobs you run on P2C will need a long time to finish(or your ssh session freezes due to network instability). When you connect to a cluster remotely (using SSH for example) and start your job, you will have to run the task in the background (adding & at the end of the command line) in order to logout of the SSH session without terminating your job early. An alternative way is to use Screen.

(HINT: To escape from a frozen ssh session press in sequence: [ENTER] [~] [.] )

Screen allows you to have multiple shell sessions(multiplexing) within a single SSH session. You don't have to start multiple SSH sessions if you need to run several commands. A common use case is when running the same program several times but with different parameters. Let us try an example.

1. Connect to the cluster using SSH.

2. Once you are logged in, create a new screen session using the command below. The -S option specifies the name of he screen session, in the example it is session-01
$screen -S session-01

3. Run a command continuously. Simple check the memory usage.
$watch free

4. Detach from the session by pressing Ctrl-a, d (Press 'Ctrl' and 'a' at the same time, release, then press 'd'). You will be returned to your SSH login shell.  Alternatively you can close the terminal where you ssh'd then go directly to step 7.

5. View the list of available screens. You can create additional screens using step 2.
$screen -list

6. Exit from SSH.
$exit

7. Connect using SSH again. Once logged in, view the available screens.
$screen -list

8. Re attach to the session-01 screen.
$screen -r session-01

9. You will observe that the watch command is still running even after you logged out of SSH. For more information read the man page of the Screen command. You can exit the screen session using exit.