Contents
Screen
screen is a terminal multiplexer that allows you to start a terminal session and then "detach" from it. This is essential for HPC work because it allows long-running processes (like data transfers or local compilations) to continue running even if your SSH connection drops.
Basic Usage
To start a standard session, simply type:
screen
It is highly recommended to name your sessions so you can easily identify them later:
# Start a session named 'analysis_session'
screen -S analysis_session
screen -S analysis_session
Note: Once you run the command, your terminal will clear. You are now inside a virtual terminal that lives on the server.
The Control Sequence
Most screen commands start with the "escape" sequence: Ctrl + A.
| Action | Key Command |
|---|---|
| Detach (Leave session running in background) | Ctrl + A then D |
| Create New Window | Ctrl + A then C |
| Next Window | Ctrl + A then N |
| Kill Current Window | Ctrl + A then K |
Managing Sessions
If you have detached from a session, you can resume it using these commands:
List Active Sessions
screen -ls
Reattach to a Session
screen -r session_name
Pro Tip: If a session is stuck as "Attached", use screen -d -r session_name to force detach it remotely and reattach locally.
Example Workflow: Long Data Transfer
# 1. Start a named session
screen -S rsync_data
# 2. Start your command
rsync -avz /local/path/ user@hpc:/remote/path/
# 3. Detach (Ctrl + A then D)
# You can now safely close your terminal or turn off your laptop.
# 4. Reattach later to check progress
screen -r rsync_data
screen -S rsync_data
# 2. Start your command
rsync -avz /local/path/ user@hpc:/remote/path/
# 3. Detach (Ctrl + A then D)
# You can now safely close your terminal or turn off your laptop.
# 4. Reattach later to check progress
screen -r rsync_data
Final Tip: screen is your insurance policy against bad Wi-Fi. If your network connection is unstable, always start your critical work inside a screen session!