Screen: Difference between revisions

From UMIACS
Jump to navigation Jump to search
No edit summary
 
(5 intermediate revisions by 3 users not shown)
Line 1: Line 1:
=== Introduction ===
=== Introduction ===
GNU Screen, or "screen", is a window management program available on UMIACS Linux hosts that allows multiplexing of a single terminal between multiple virtual consoles. Screen is also capable of separating programs from the shell that initially started it which allows a program to continue running even if the connection to the host has been lost. For this reason screen is typically used when a network connection is unstable and the process must remain running even if an SSH connection has dropped.  
GNU Screen, or "screen", is a window management program available on UMIACS Linux hosts that allows multiplexing of a single terminal between multiple virtual consoles. Screen is also capable of separating programs from the shell that initially started it which allows a program to continue running even if the connection to the host has been lost. For this reason screen is typically used when a network connection is unstable and the process must remain running even if an SSH connection has dropped. Screen is also useful when a process may be slow and other processes need to be running.  


=== Usage ===
=== Usage ===
Line 21: Line 21:


The output will be similar to this:
The output will be similar to this:
  # claw@idaho:~$ screen -ls
  # username@tron02:~$ screen -ls
  #  There are screens on:
  #  There are screens on:
  # 26598.screenTest1 (Detached)
  # 26598.screenTest1 (Detached)
  # 18457.pts-0.idaho (Detached)
  # 18457.pts-0.tron02 (Detached)
  # 2 Sockets in /var/run/screen/S-claw.
  # 2 Sockets in /var/run/screen/S-username.


To reconnect to a specific screen session you may use either the screen number or name to reconnect using ‘screen -r’
To reconnect to a specific screen session you may use either the screen number or name to reconnect using ‘screen -r’
  # claw@idaho:~$ screen -r 26598
  # username@tron02:~$ screen -r 26598


or
or


  # claw@idaho:~$ screen -r screenTest1
  # username@tron02:~$ screen -r screenTest1
 


===Common Keyboard Shortcuts===
===Common Keyboard Shortcuts===
Line 40: Line 39:
* Ctrl-A + c (Creates a new window.)
* Ctrl-A + c (Creates a new window.)
* Ctrl-A + d (detach from current session)
* Ctrl-A + d (detach from current session)
* Ctrl-A + [0-9] (Switches to the window corresonding to the number, window 0 is the first window initialized by screen.)
* Ctrl-A + [0-9] (Switches to the window corresponding to the number, window 0 is the first window initialized by screen.)
* Ctrl-A + " (Presents a selection of screen windows from which to choose.)
* Ctrl-A + " (Presents a selection of screen windows from which to choose.)
* Ctrl-A + Shift-A Rename the current screen window
* Ctrl-A + Shift-A Rename the current screen window
Line 50: Line 49:


=== Important Notes ===
=== Important Notes ===
If you start a program within a screen session that has only one window then when the program exits the screen session will terminate as well. This has the potential to hide any output you may want from your program since the screen session will exit. To solve this issue you can either make sure your shell is not set to auto-logout, or ensure that you have multiple windows open in the screen session so that it will not terminate when the program exits.
If you start a screen session that will run a program within a session that has only one window, such as by issuing the command
# screen program.c
then when the program exits the screen session will terminate as well. This has the potential to hide any output you may want from your program since the screen session will exit. To solve this issue you can either make sure your shell is not set to auto-logout, or ensure that you have multiple windows open in the screen session so that it will not terminate when the program exits.


=== .screenrc ===
=== .screenrc ===
Similar to .bashrc, the file .screenrc in a user's home directory can be used to customize each screen session's startup behavior.  Commands listed in this file will be executed upon starting screen. See the link [http://www.gnu.org/software/screen/manual/screen.txt  here] for more information about screen commands (Section 5.2: Command Summary).
Similar to .bashrc, the file .screenrc in a user's home directory can be used to customize a screen session's startup behavior.  Commands listed in this file will be executed upon starting screen, and can be useful to set up your environment to display important information such as the window number and name, the name of the host you're connected to, or altering the key sequences for screen commands. See the link [http://www.gnu.org/software/screen/manual/screen.txt  here] for more information about screen commands (Section 5.2: Command Summary).


=== Useful Links ===
=== Useful Links ===
* [http://www.gnu.org/software/screen/ The main page at www.gnu.org.]
* [http://www.gnu.org/software/screen/ The main page at www.gnu.org.]
* [http://www.gnu.org/software/screen/manual/screen.txt GNU Screen documentation] (also accessed through '''man screen''').
* [http://www.gnu.org/software/screen/manual/screen.txt GNU Screen documentation] (also accessed through '''man screen''').

Latest revision as of 15:16, 22 April 2022

Introduction

GNU Screen, or "screen", is a window management program available on UMIACS Linux hosts that allows multiplexing of a single terminal between multiple virtual consoles. Screen is also capable of separating programs from the shell that initially started it which allows a program to continue running even if the connection to the host has been lost. For this reason screen is typically used when a network connection is unstable and the process must remain running even if an SSH connection has dropped. Screen is also useful when a process may be slow and other processes need to be running.

Usage

To invoke screen, simply use the following command in a terminal:

# screen

Alternatively, to start a program with screen:

# screen vi program.c

This will invoke screen and, in the newly-created window, start editing the file program.c in vi.

You can have as many screen sessions as you’d like on a single host, however, keeping track of many sessions can become difficult. As a way to solve this screen offers the capability to give each session a unique name when you start it using the following:

# screen -S [session name]

If you need to end your ssh session, but want your processes to keep running you can detach the screen session with:

# screen -d

Then exit as normal.

If you have multiple screen sessions you can detach and reattach them at any time. To list the current screen sessions running on a host use:

# screen -ls

The output will be similar to this:

# username@tron02:~$ screen -ls
#  There are screens on:
# 	26598.screenTest1	(Detached)
# 	18457.pts-0.tron02	(Detached)
# 2 Sockets in /var/run/screen/S-username.

To reconnect to a specific screen session you may use either the screen number or name to reconnect using ‘screen -r’

# username@tron02:~$ screen -r 26598

or

# username@tron02:~$ screen -r screenTest1

Common Keyboard Shortcuts

Ctrl-A is the metacharacter for commands in screen; press it before every key command. Some useful commands in screen:

  • Ctrl-A + c (Creates a new window.)
  • Ctrl-A + d (detach from current session)
  • Ctrl-A + [0-9] (Switches to the window corresponding to the number, window 0 is the first window initialized by screen.)
  • Ctrl-A + " (Presents a selection of screen windows from which to choose.)
  • Ctrl-A + Shift-A Rename the current screen window
  • Ctrl-A + <SPC> / Ctrl-A + <BKSPC> (Switch to the next / previous window.)
  • Ctrl-A + k (Kill the current window.)
  • Ctrl-A + \ (Kill the screen session and all its windows.)

See the documentation here to see a full list of Ctrl-A commands (Section 5.1: Default Key Bindings).

Important Notes

If you start a screen session that will run a program within a session that has only one window, such as by issuing the command

# screen program.c 

then when the program exits the screen session will terminate as well. This has the potential to hide any output you may want from your program since the screen session will exit. To solve this issue you can either make sure your shell is not set to auto-logout, or ensure that you have multiple windows open in the screen session so that it will not terminate when the program exits.

.screenrc

Similar to .bashrc, the file .screenrc in a user's home directory can be used to customize a screen session's startup behavior. Commands listed in this file will be executed upon starting screen, and can be useful to set up your environment to display important information such as the window number and name, the name of the host you're connected to, or altering the key sequences for screen commands. See the link here for more information about screen commands (Section 5.2: Command Summary).

Useful Links