Intermediate · 8 min · practise every command in the built-in terminal

Background Jobs

Linux lets you run multiple tasks in one terminal.

Run in background

command &           # Start in background

Output: [1] 12345 — job number and PID

Job control

jobs               # List background jobs
bg %1              # Resume job 1 in background
fg %1              # Bring job 1 to foreground
fg                 # Bring most recent job to foreground

Suspend and resume

  1. Run a command in foreground
  2. Press Ctrl+Z to pause it
  3. Type bg to resume it in background
  4. Type fg to bring it back

nohup — Run after logout

nohup command &                        # Run even after logout
nohup python3 server.py > server.log &

Output goes to nohup.out by default.

disown — Detach from shell

command &
disown %1           # Detach from shell

Practical example

# Start a long download in background
wget https://example.com/bigfile.zip &

# Check progress
jobs

# Bring to foreground to see output
fg %1

Practice tasks

  1. Start 'sleep 60' in the background
  2. List your background jobs
  3. Start two background jobs at once
  4. Bring the most recent background job to the foreground

Commands in this lesson

Processes