nohup and screen
You start a long process, close your laptop, and... it dies. SSH disconnects, and your 6-hour job terminates.
Let's fix that.
The Problem
When you log out or disconnect:
- Your shell receives SIGHUP
- Shell sends SIGHUP to all its children
- Children terminate
This is why closing your terminal kills your processes.
nohup - Ignore Hangup
nohup makes the process immune to SIGHUP. It keeps running when you log out.
Where Does Output Go?
disown - Detach Existing Process
Forgot nohup? Already started the process?
disown removes the job from the shell's job table.
screen - Terminal Multiplexer
screen creates persistent terminal sessions you can detach from and reattach later.
Basic Usage
Reattaching
Multiple Sessions
Named Sessions
screen Keyboard
All screen commands start with Ctrl+A:
Ctrl+A D= DetachCtrl+A C= New windowCtrl+A N= Next windowCtrl+A P= Previous windowCtrl+A K= Kill window
tmux - Modern Alternative
tmux is like screen but more powerful and is the modern standard:
tmux Key Commands
All tmux commands start with Ctrl+B:
Ctrl+B D= DetachCtrl+B C= New windowCtrl+B N= Next windowCtrl+B %= Split pane verticallyCtrl+B "= Split pane horizontallyCtrl+B Arrow= Switch between panes
Named Sessions
tmux new -s deploy # Create named session
tmux attach -t deploy # Attach by name
tmux ls # List sessions
tmux kill-session -t deploy # Kill session
tmux is the Standard
Most DevOps professionals use tmux over screen. It has better pane splitting, more intuitive defaults, and excellent plugin support. Learn tmux - you'll use it daily.
When to Use Which
| Tool | Use Case |
|---|---|
nohup | Simple, one-off commands |
disown | Already running, forgot nohup |
screen | Interactive work, need to return |
tmux | Same as screen, more features |
What happens when you SSH to a server, run a command, and close your laptop?
Quick Reference
| Command | Effect |
|---|---|
nohup cmd & | Run immune to hangup |
disown | Detach current job from shell |
screen | Start multiplexer session |
Ctrl+A D | Detach from screen |
screen -r | Reattach to screen |
tmux | Start tmux session |
Ctrl+B D | Detach from tmux |
Key Takeaways
- Processes die when their parent shell dies (SIGHUP)
nohupmakes processes immune to hangupdisowndetaches already-running processesscreen/tmuxcreate persistent sessions- Use these for any long-running remote work
Congratulations! You've completed Chapter 7: Process Management.
Next chapter: System Information - checking disk, memory, and CPU.