Skip to content

Screen

If you ssh to one of the SuperCloud login nodes and need to run a script or command(s) that you expect to take a while to complete, you should use the Linux screen command which will keep processes running even if you lose your connection. If your ssh connection drops for some reason, screen allows you to reattach to a previous session so you can finish your task.

If you will be doing a lot of work in an interactive session on a compute node, you should also use the screen command so that your interactive session isn't killed if you lose your connection.

Remember your login node

It is important to make a note of which login node you are logged into when you issue the screen command. If you lose your connection, you will have to log back into the same login node in order to find and restore your screen session.

To see which login node you are currently logged into, from your ssh terminal, run:

$ echo $HOSTNAME
login-4

If you lose your ssh connection and need to restore your screen session, you'll have to log back in to the same login node you were on when you created your screen session:

$ ssh USERNAME@txe1-login4.mit.edu

Using screen

Here are the very basics that you need to know in order to use the screen command.  You can find a more detailed introduction to screen here (ignore the sections on installing it; it is already installed on SuperCloud).

Create a screen session

With screen you can create one or more sessions in your current SSH terminal. To start it, just run:

$ screen

This creates a screen session in your current ssh terminal.

Here are the most important screen commands that you need to control screen. These commands begin with CTRL-a to distinguish them from normal shell commands.

Ctrl-a c    Create a new screen session so that you can use more than one screen session at once. Ctrl-a n    Switch to the next screen session (if you use more than one). Ctrl-a p    Switch to the previous screen session (if you use more than one). Ctrl-a d    Detach a screen session (without killing the processes in it - they continue).

To close a screen session where all tasks are finished, type:

exit

Get a list of your screen sessions

Back in a regular ssh terminal on the login node where you created your screen session, you can get a list of your current screen sessions by typing:

$ screen -ls
There is a screen on:
        76645.pts-46.login-4 (Detached)
1 Socket in /run/screen/S-AN23082.

Reconnect to a screen session

To reconnect to the session, make sure you are logged in to the proper login node, then run:

$ screen -r 76645