Screen

Screen is a window manager that allows you to have multiple shells running in one terminal window. When screen is called, it creates a new shell so that you can use the program independently of the currently running shell. And at any time, you can detach, resume or switch the shells without terminating the running programs. For more information, please check the screen user's manual https://www.gnu.org/software/screen/manual/screen.html.

Basic Usage

Here is the basic usage of screen. First, create a new session:

screen -S demo

We now switch to a new screen shell. This new session named demo and runs independently. To print the list of sessions, we can use:

screen -ls

There is a screen on:

22087.demo (04/18/2017 11:36:31 AM) (Attached)

1 Socket in /var/run/screen/S-ryli.

Sessions marked 'Attached' are running. Here we have one session named demo with id 22087. We can run any program in this new session, e.g., show the GPUs' information:

nvidia-smi -l

This program shows the GPUs' information every 5 seconds. We now detach this session without terminating the nvidia-smi program:

Control-a d
# hold down the 'Control' key, press and release the 'a' key, and then type 'd'

If we print the list of sessions again:

screen -ls

we can see the following:

There is a screen on:

22087.demo (04/18/2017 11:36:30 AM) (Detached)

1 Socket in /var/run/screen/S-ryli.

The demo session marked 'Detached' is running in the background and can be easily resumed by typing:

screen -r demo

The terminal will switch back to the demo session and the nvidia-smi program is still running. After we terminating the currently running nvidia-smi program by Control-c, we can kill the session:

exit

There is no session when we show the list:

screen -ls

No Sockets found in /var/run/screen/S-ryli.

Some Useful Commands

Here are some commonly used commands in screen.

List all the sessions

screen -ls

Create new session

screen -S #sessionname#

Resume a session

screen -r #sessionname/sessionid#

Detach from a session

Control+a d

Kill a running session

Control+a k

or

exit

Enter copy mode

Control+a [

Once we enter the copy mode, we can do the following things.

  • Scroll forward one screen: Control+f
  • Scroll back one screen : Control+b
  • Move to beginning of session: 0
  • Move to end of session: $
  • Exit: exit

results matching ""

    No results matching ""