AcademyTerminal Tactics: Survival in the ShellPhase 3: Ghost in the Machine (Processes)

Lesson 2: The Juggler (Background & Foreground)

A DevOps engineer doesn't just run one command at a time — they juggle multiple processes like a circus performer. Understanding foreground and background processes is the key to multitasking in the terminal.

Foreground vs. Background

  • Foreground: The command takes over your terminal. You can't type anything else until it finishes.
  • Background: The command runs silently while you continue working.

The Magic Ampersand: &

Add & at the end of any command to run it in the background:

sleep 300 &

This starts a 5-minute sleep timer without blocking your terminal.

Job Control Commands

  • jobs — List all background jobs in the current session.
  • fg %1 — Bring job #1 back to the foreground.
  • bg %1 — Resume a paused job in the background.
  • Ctrl + Z — Pause (suspend) the current foreground process.

The nohup Command

When you close your terminal, all your background jobs die. To keep a process running even after logout:

nohup ./my-script.sh &

nohup = "No Hang Up". Essential for long-running deployments.

booting...

Mission Objective

You need to run a long monitoring task while continuing to work:

  1. Start juggling: Run sleep 300 & to create a background process.
  2. Check your act: Run jobs to see it running in the background.
  3. Take control: Bring it back to the foreground with fg %1.

Mission Control

Start a background process

Expected Command

sleep 300 &

List all background jobs

Bring the job to foreground