Skip to content

tmux & screen for Long Jobs

When you run long simulations or big code batches on a remote server, you don’t want everything to stop just because your internet disconnects or your laptop goes to sleep. That’s where tmux and screen come in — they let you keep your sessions running in the background, even if you close your terminal.

Think of them like a “pause button” for your terminal — you can leave, come back later, and everything is exactly as you left it.

Why You Need Them

Let’s say you start a simulation that takes 4 hours. Two hours in, your Wi-Fi drops. Normally, your SSH session would close — and your simulation would stop. Painful, right?

If you had started that simulation inside tmux or screen, it would keep running on the server, even while you’re offline. Later, you can reconnect and continue right where you left off.

Important: Always start tmux or screen after logging in to your remote server via SSH.
Running them locally won’t help — they need to be started inside the remote terminal.

Using tmux (the modern favorite)

tmux is lightweight, fast, and works on almost every Linux and macOS terminal.

Start a new session

bash
tmux

You’ll see a new terminal — that’s your tmux session. Run whatever long command or simulation you want inside it.

Detach (leave it running)

Press:

Ctrl + B, then D

This “detaches” you from the session — your program keeps running in the background.

Reattach (come back later)

bash
tmux attach

You’ll reconnect to your running session — everything is just as you left it.

List all sessions

bash
tmux ls

Kill a session

bash
tmux kill-session -t 0

(Replace 0 with your session name or number.)

Using screen (the classic alternative)

If you prefer something simpler or your system doesn’t have tmux, use screen.

Start a session

bash
screen

Detach

Press:

Ctrl + A, then D

Reattach

bash
screen -r

List sessions

bash
screen -ls

End a session

Inside the screen, type:

bash
exit

Real-World Example

You’re logged into your remote server and want to run a long FEniCS simulation:

bash
tmux
python3 main_elasticity.py

Then detach (Ctrl + B, D), close your laptop, and go about your day. When you reconnect later:

bash
ssh username@server_ip
tmux attach

Boom — your code is still running, or maybe it’s already finished, waiting for you to check results.

Notes

  • tmux is generally preferred — it’s newer, more flexible, and supports multiple panes or split windows.
  • You can have multiple sessions running — useful for testing different cases at once.
  • If you forget your session name, tmux ls or screen -ls will show you all active ones.
  • To exit cleanly, type exit inside your session — that closes it properly.
  • Works great with SSH — perfect for remote jobs or cloud simulations.

Summary

  • tmux and screen let your long jobs keep running even if you disconnect or close your terminal.
  • You can detach anytime, reconnect later, and pick up right where you left off.
  • They’re essential for anyone running remote simulations, cloud workloads, or any long-running scripts.

Once you get used to them, you’ll wonder how you ever managed without these simple, reliable tools for uninterrupted computing.