LAB-PROC-04 - Foreground and Background Jobs
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
Prerequisites
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
- Run
ping localhost - Press
Ctrl+Z - Run
jobs - Notice the command is stopped, not gone
Exercise G2: Resume it in the background
- Run
bg - Run
jobs - Notice the job is now running in the background
Exercise G3: Bring it back and stop it cleanly
- Run
fg - The command returns to the foreground
- Press
Ctrl+Cto stop it
S Solo Task described, hints available - figure it out >
Exercise S1: Start directly in the background
- Run
sleep 120 & - Run
jobs - Bring it back with
fg - Stop it with
Ctrl+C
Exercise S2: Reason about persistence
Answer in words:
- why a simple background job may still die when the shell exits
- when
nohupwould be better - when
tmuxwould 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:
- you only want your prompt back for a minute
- you are on a remote server and want to reconnect later to the same session
- 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.