Skip to main content

Using Screen

This is a quick overview on how to use screen to keep processes running even if you log out of the SSH session.

NOTE: Do not update this page. This page is soft linked to IT - Sysadmin > Linux > Using Screen. If you want to change the contents of this page, please change it on that page instead.

This is a quick overview on how to use screen to keep processes running even if you log out of the SSH session.

NOTE: Do not update this page. This page is soft linked to IT - Sysadmin > IT - Public How-To's > Linux > How To Use Screen. If you want to change the contents of this page, please change it on that page instead.


Normally if you leave an SSH session, everything that is running will get killed. If you want to have a process continue to run you will need to use a program like screen. This will create a persistent session that stays running even after you log out of your ssh session

Commands

Launching a Screen Session

To launch a screen session run:

screen -S <name>
# Example
screen -S project1

The name can be whatever you want as long as there is no spaces. You will use this to identify and reconnect to your session at a later time.

After hitting enter it will look like a normal command line, go ahead and run whatever long process you were going to here

Detaching From a Screen Session

This is like the minimize button in Windows, your screen session is still running in the background.

After running your program, you will probably want to detach from the screen session to do other things. The easiest way is to just close your ssh window.

To detach the session press ctrl + a, let go of the keys and then press d. This will send you back to your normal ssh session.

Do not type exit or logout in a screen session until you are ready to end the screen session. exit and logout will cause screen to terminate and take you back to the normal ssh session.

Exiting Screen Sessions

As stated above, to terminate the screen session and all commands running within it type exit or logout. Screen will exit and kill any processes running in it.

Listing Your Active Screen Sessions

You may want to see what sessions you have active. To do this run:

screen -ls

In the example below I have 2 screen sessions. One named test, and one named project1:

[amdhome@mercury ~]$ screen -ls
There is a screen on:
        9955.test       (Detached)
        9971.project1   (Detached)
1 Socket in /var/run/screen/S-amdhome.

Reattaching to a Screen Session

To reattach to your screen session run:

screen -r <name>
# Example
screen -r project1

This should take you back to your screen session

Scrolling in a screen window

Sometimes you need to scroll up in a screen window, but screen won't let you by default.

To scroll press ctrl + a let go of the keys and then press esc. You should now be able to scroll with your arrow keys