Script Valley
Linux & Bash for Developers
Process Management & System MonitoringLesson 4.4

Background jobs and job control in Bash

background with &, jobs command, fg bg, nohup, disown, screen tmux overview, Ctrl+Z, process groups

Run Processes in the Background

By default a command runs in the foreground — it holds your terminal until it completes. Append & to run it in the background and get your prompt back immediately. Use job control to manage multiple running tasks in a single terminal session.

Job Control Commands

# Run in background
python3 server.py &

# List all background jobs
jobs
# Output: [1]+ Running   python3 server.py &

# Bring job 1 to foreground
fg %1

# Suspend foreground process (Ctrl+Z), then send to background
# Press Ctrl+Z first, then:
bg %1

# Get the PID of the last background process
echo $!

Surviving Terminal Disconnection

Background jobs are tied to your terminal session. If your SSH connection drops, they are killed. Use nohup to detach from the terminal, or disown after backgrounding.

# Run a long job that survives logout
nohup ./long_process.sh > output.log 2>&1 &

# Disown a job already running in background
python3 server.py &
disown %1

# Better long-term solution: tmux
tmux new -s mysession
# Run your process inside tmux
# Detach with Ctrl+B then D
# Reconnect later with: tmux attach -t mysession

Up next

How to check disk usage in Linux with df and du

Sign in to track progress