Practice Use drills for recall and labs for real operating judgment.

LAB-PROC-04 - Foreground and Background Jobs

Practice basic bash job control so you can pause, resume, background, and foreground simple commands without panic.

PS Process Management

Foreground and Background Jobs

Practice basic bash job control so you can pause, resume, background, and foreground simple commands without panic.

30 min INTERMEDIATE LINUX Curriculum-reviewed
Success criteria
  • Pause and resume a foreground job.
  • Explain why a background job is not necessarily persistent.
Safety notes
  • Use only harmless lab commands such as sleep or ping in this exercise.

Part A: The Field Guide

Job control helps you manage the relationship between a command and your current terminal.

This lab keeps the scope simple:

  • pause a foreground command
  • move it to the background
  • bring it back
  • explain why terminal job control is not the same as persistence across disconnects

Key Distinction

bg and fg are about this shell session. Tools like nohup, tmux, or services are about surviving beyond it.


Part B: The Drill Deck

Terminal required: keep the examples harmless.

G
Guided Step by step - type exactly this and compare the result
>

Exercise G1: Pause a foreground command

  1. Run ping localhost
  2. Press Ctrl+Z
  3. Run jobs
  4. Notice the command is stopped, not gone

Exercise G2: Resume it in the background

  1. Run bg
  2. Run jobs
  3. Notice the job is now running in the background

Exercise G3: Bring it back and stop it cleanly

  1. Run fg
  2. The command returns to the foreground
  3. Press Ctrl+C to stop it
S
Solo Task described, hints available - figure it out
>

Exercise S1: Start directly in the background

  1. Run sleep 120 &
  2. Run jobs
  3. Bring it back with fg
  4. Stop it with Ctrl+C

Exercise S2: Reason about persistence

Answer in words:

  1. why a simple background job may still die when the shell exits
  2. when nohup would be better
  3. when tmux would be better
M
Mission Real scenario - no hints, combine multiple skills
>

Mission M1: Explain the right tool choice

For each situation, name the best first tool:

  1. you only want your prompt back for a minute
  2. you are on a remote server and want to reconnect later to the same session
  3. you want a real long-lived service that restarts automatically

If you can choose among job control, tmux, and services correctly, the process section is becoming practical.