Intermediate · 25 minutes · Guided lesson

Processes, jobs and resource pressure

Inspect a process you own and stop it gracefully using its exact PID.

By the end of this lesson

  • Distinguish a shell job from a system process
  • Find a specific process by PID
  • Use a graceful signal before considering forced termination

Your environment: Bash with procps ps. Minimal BusyBox ps may not support the same output options. Setup help

Follow the process, not a guess

A process is a running program instance with a process ID, an owner and resource usage. A job is the shell’s way of managing one or more processes it started. The jobs command only knows about the current shell’s jobs; ps provides a wider process view. Do not assume a PID copied from yesterday still belongs to the same process.

Background work allows the prompt to return while the process continues. In Bash, $! is the PID of the most recent background process. Save it immediately when you need to inspect that process later, and verify its command and owner before sending a signal.

Interpret resource data in context

Load average is not a CPU percentage: runnable tasks and some waiting tasks contribute. A high value needs context such as CPU count, storage latency and what changed. Likewise, Linux uses memory for caches, so a small free figure alone does not prove a memory shortage; available memory is often more useful.

SIGTERM requests termination and gives a process a chance to clean up. SIGKILL cannot be caught and prevents normal cleanup. Neither is a universal repair. This lab starts a harmless sleep process owned by you, so you never have to select an arbitrary process from the machine.

See it in context

Worked example

Start a short-lived process and capture its ID.

sleep 300 &
lab_pid=$!
printf "Lab PID: %s\n" "$lab_pid"
ps -p "$lab_pid" -o pid,comm

The selected row should describe sleep. Your numeric PID will differ from anyone else’s.

Your turn

Practical lab

Observe a process, then end only that practice process.

Run commands in your own lab. This website displays instructions; the practice terminal below helps you rehearse the syntax.

1. Prepare your workspace

sleep 300 &
lab_pid=$!

2. Complete the task

  1. Inspect lab_pid with ps and confirm that it is sleep.
  2. View the current shell’s jobs and compare its job number with the PID.
  3. Send SIGTERM to lab_pid, wait for it, then check that it no longer appears in ps.

3. Check your result

  • You captured and inspected the PID of the process you started.
  • After termination, ps has no row for that sleep process.
  • You can explain why a non-zero wait result is expected after a signal.
Need a hint?

Keep all steps in the same terminal so the lab_pid variable and shell job still exist.

Reveal a worked solution

Compare this with your approach after trying the task. More than one valid solution may exist.

ps -p "$lab_pid" -o pid,comm
jobs
kill -TERM "$lab_pid"
wait "$lab_pid"
ps -p "$lab_pid" -o pid,comm

After the lab: If the sleep is still running, confirm its identity again before terminating it. Otherwise it expires automatically.

Common mistakes to avoid

  • Never copy an arbitrary PID from a tutorial into kill.
  • A shell variable is not shared automatically between separate terminal windows.

Check your understanding

Knowledge check

Answer all 3 questions correctly to pass. Retry as often as you need; your best score is kept.

1. What does $! represent in Bash?
2. Which signal normally gives a process a chance to clean up?
3. Does high load alone prove CPU saturation?

Your lesson progress

Not started · Best score: 0% · Attempts: 0

Practical completion is self-reported. Progress is linked to a private cookie in this browser and stored on the site. Clearing that cookie loses access to it. Manage or erase progress.

Keep the reference close

Further reading