Child pages
  • Screen- CHPC Software Use- use of Linux command "screen"

Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.

All CHPC Software


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 screen will start a 'screen' session. The session will look like a plain terminal session and you should be looking at a normal prompt.

You can type screen -ls at any time, and you should see a listing of all the 'screen' sessions that are currently active. For example:

Code Block
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.

Each 'screen' session is identified with the process id number, followed by an informational piece that can be customized. 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 gaussian:

Code Block
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 special commands. In order to execute any command, you must first press 'ctrl+a', followed by a key that indicates the command. For example, ctrl+a, followed by ? will give a help screen (note that the carrot symbol (^) means 'ctrl'):

Code Block
Command key: ^A Literal ^A: a

break ^B b	 fit F 		kill K 		monitor M 		prev ^P p ^? 	silence _ 	width W
clear C		 flow ^F f	lastmsg ^M m 	next ^@ ^N sp n 	readbuf < 	split S 	windows ^W w
colon :		 focus ^I 	license , 	number N		redisplay ^L l 	suspend ^Z z 	wrap ^R r
copy ^[ [ 	 hardcopy h 	lockscreen X 	only Q 			removebuf = 	time ^T t 	writebuf >
detach ^D d 	 help ? 	log H 		other ^A 		reset Z 	title A 	xoff ^S s
digraph ^V 	 history { } 	login L 	pow_break B 		screen ^C c 	vbell ^G 	xon ^Q q
displays * 	 info i 	meta a 		pow_detach D 		select ' 	version v

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: ctrl+a d. You can also type screen -d to accomplish the same. This detaches the 'screen' and drops you back to the shell from which you started the 'screen' session. Processes running within these detached 'screen' sessions will continue to operate as normal. You can exit from the ssh session and leave the screens going and come back to them at any time and from any other ssh session. This allows you to avoid complications from suspended ssh sessions or other possible mishaps (like disconnects).

To come back to the screen session at a later time, log in to the node you set the screen session up on and type screen -r. If you have more than one screen running, you can use screen -r 14839.pts-5.icebox1  as in the example above, substituting your session name.

To end 'screen' sessions you just type exit as you normally would to end a terminal session. This will terminate any programs you have running in the screen session, so make sure you're done with the session before you close. 
Documentation has been moved:

This includes a searchable database found: