Process Management – Linux Teaching Plan

This 2‑hour module introduces students to the most commonly used tools for viewing, controlling and troubleshooting Linux processes. Students will gain hands‑on experience by launching, manipulating and profiling simple programs.

Learning Objectives

Schedule & Topics

  1. Intro & PID concepts (5 min)
  2. Listing – ps (10 min)
  3. Tree view – pstree (5 min)
  4. Top‑like monitor – top (10 min)
  5. Interactive monitor – htop (10 min)
  6. Signal sending – kill (10 min)
  7. Job control – bg, fg, jobs (10 min)
  8. Process affinity – taskset (10 min)
  9. Priority control – nice/ renice (10 min)
  10. Tracing – strace (10 min)
  11. Monitoring – systemctl status & systemctl start/stop (10 min)
  12. Mini‑project: “Create & manage a sample service” (15 min)
  13. Q&A & wrap‑up (5 min)

Command Topics & Hands‑On Exercises

1. ps – View Current Processes

Shows the state of processes running in a shell.

ps aux
ps -ef

2. pstree – Process Hierarchy

Displays processes as a tree.

pstree -p
pstree -s 1234

3. top – Interactive CPU/Memory Monitor

Updates every 3 s by default.

top
top -p 1234

4. htop – User‑friendly Top

Requires installation on some distros.

sudo apt install htop
htop

5. kill – Send a Signal

Send signals to processes.

kill 1234          # SIGTERM
kill -KILL 1234    # SIGKILL
kill -USR1 1234

6. pkill / killall – Kill by Name

Terminates processes matching a pattern.

pkill -f "sleep 200"
killall -u bob  # kill all bob's processes

7. bg, fg, jobs – Job Control

Manage jobs started from the interactive shell.

sleep 300 &
jobs
fg %1
bg %1
kill %1

8. nice / renice – Process Priority

Adjusts scheduling priority.

nice -n 10 long_running_task &
renice -n -5 1234

9. ps -o – Custom Output

Show only selected fields.

ps -e -o pid,ppid,cmd,stat

10. top -d – Custom Refresh Interval

Set the refresh interval to 5 s.

top -d 5

11. pstree -A – ASCII Tree

Displays a compact tree with ASCII characters.

pstree -A -p

12. strace – System Call Tracing

Shows the system calls made by a program.

strace -p 1234
strace -e trace=read,write -o trace.log sleep 10

13. top -p – Monitor a Single PID

Focuses on a specific process.

top -p 1234

14. systemctl status – Service Process Info

Shows the status of systemd units and their main PID.

sudo systemctl start ssh
systemctl status ssh

15. ps -f – Full Format

Displays the full command line and process ancestry.

ps -f --forest
ps -f -C bash

Mini‑Project: “Process‑Based Service Lab”

Students write a small script that:

  1. Starts a long‑running background task (e.g., a simple Python HTTP server).
  2. Logs its PID to a file.
  3. Prints a friendly message when the process dies (by trapping SIGTERM).
  4. Provides commands to view its CPU and memory usage (`top -p`, `ps`, `htop`).

They will then:

Assessment

  1. Quiz (5 min) – 5 quick questions about signals and process states.
  2. Hands‑on lab (10 min) – create, suspend, resume, and kill a process; use `ps` to confirm.
  3. Script demonstration (10 min) – each student runs their process‑service script and explains the output.

Resources

Feel free to tweak the project or add optional tools such as systemd-run or ulimit for more advanced process‑management concepts.