CHPC Software: Use of Linux command "screen"

This document is to introduce users to the 'screen' command and help give some ideas of where it might be useful to use. The 'screen' tool allows a user to start up multiple shell sessions on a computer. There are a few points of value from using screen to do this vs just using something like ssh or xterm. One of the most important values is that 'screen' sessions will continue operation even if you loose connection to the remote system your running 'screen' on.

CHPC strongly suggests that users consider using screen for running applications or commands from a remote session that may be active for a long period of time. We will outline a few core features of using 'screen' in this document. However a thorough resource on 'screen' is available by viewing the 'screen' manpage. Simply typing:


will start a 'screen' session. The session will look like a plain terminal session and you should be looking at a normal prompt. At any time if you type:

screen -ls

you should see a listing of all the 'screen' sessions that are currently active. For example:

[erik@icebox1 ~]$screen -ls
There are screens on:
         14839.pts-5.icebox1     (Detached)
         14904.pts-5.icebox1     (Attached)
2 Sockets in /tmp/uscreens/S-erik.

These 'screen' sessions when started are identified with the process id number followed by an informational piece that can be customized with a flag. To make the sessions more easily identifiable 'screen' can be started with a -S flag to give the session id an identifier that is more easily recognized. For example:

screen -S gaussian

will give you a session that is listed as:

[erik@icebox1 ~]$screen -ls
There are screens on:
         15288.gaussian  (Attached)
         14839.pts-5.icebox1     (Detached)
         14904.pts-5.icebox1     (Attached)
3 Sockets in /tmp/uscreens/S-erik.

All commands given to 'screen' are given with controll comannds. The base command to communicate with 'screen' is given by holding down the control key and pressing the a key (ctrl-a, hereafter defined as: C-a). To get a listing of all commands available to 'screen' you can type

C-a ?

Once you begin your application within your 'screen' session you are able to detatch from the session without closing your application. To do this you simply type:

C-a d

This issues a detach command to 'screen' and drops you back to the shell from which you started the 'screen' session. Attatched and detached sessions can be seen in the above examples. Processes running within these detached 'screen' sessions will continue to operate as normal. You can exit from the node and leave sessions going and come back to them at any time and from any other ssh session to that node. This allows you to avoid complications from suspended ssh sessions or other possible mishaps. To come back to the session at a later time you can reattach to the 'screen' session by returning to the node you were using (if you had left it) and typing:

screen -r 

In the example above a screen -r 14839.pts-5.icebox1 would reattach to the detached session. From there it is if you had never detatched or closed the ssh session.

To end 'screen' sessions you just type exit as you normally would to end a terminal session.

Last Modified: October 06, 2008 @ 21:07:48