Jump to content

toolserver:Screen

From mediawiki.org

This page was moved from the Toolserver wiki.
Toolserver has been replaced by Toolforge. As such, the instructions here may no longer work, but may still be of historical interest.
Please help by updating examples, links, template links, etc. If a page is still relevant, move it to a normal title and leave a redirect.

Getting started

screen provides a persistent "virtual terminal" that you can run command-line programs in. This avoids the problem where you log off, or your session is interrupted for some reason, and all the programs you were running exit. If you run the programs under screen, you can simply detach the screen session, log off, then reconnect later and attach it to get your programs back.

Note: while it's possible to start a tool under screen and leave it running, this is not the right way to start tools. Once you've got the hang of using screen, see job scheduling#Running jobs under screen to see how to submit screen-based jobs.

Quick-start

[edit]

Log in to a terminal on one of the login servers.

Type

$ screen

at a terminal. You will get a new shell prompt, running inside screen. Now run your program here. When you want to log off, type CTRL+A CTRL+D to detach screen. You will see:

[screen detached]

and you're back at the old shell prompt. Now log off; your programs will continue running in screen's virtual terminal. When you want to get them back, log in again and run

$ screen -r

This will resume the detached screen.

To terminate a screen session, resume it with screen -r and then press CTRL+A CTRL+\ to kill all windows, or simply exit the shell (by typing exit or CTRL+D at the shell prompt) and screen will exit automatically.

If you run many screen sessions simultaneously, it can be helpful to name them.

$ screen -S operation1

To resume such a session:

$ screen -r operation1

Other features

[edit]
Opening multiple windows
Type CTRL+A c. A new screen will open. You can switch between screens with CTRL+A #, where # is the screen to switch to (starting from 0). All screens under the same session are detached and reattached together.
List all open windows
Type CTRL+A w.
Start a screen detached
Use screen -d -m command and the screen will start with your command running in it, but will not be attached.

For a detailed overview of screen, see the manual page screen(1).

Always use screen on login

[edit]

By changing your ~/.bash_profile to somewhat like

if [ -f ~/.bashrc ]; then
        source ~/.bashrc
fi
exec screen -D -R

you will always reattach to the same screen session (or create a new one if there's no screen running). With CTRL+C d you will detach the screen and log out. Use CTRL+d or type exit to close a screen. With the last screen closed you will log out.

Category:Commands