Python Process Monitoring: top, htop & Background Jobs
Real-time process monitors like `top` and `htop` display dynamic system metrics including CPU utilization, memory consumption, load averages, and per-process threads. In Bash, jobs can be sent to the background with `&`, suspended with Ctrl+Z, and resumed via `bg` and `fg`.
"`ps` is a static photograph of traffic at a single second; `top` is a live CCTV video feed continuously tracking cars driving on the highway."
Deep Dive: How It Works
Load Average: Three numbers representing average runnable tasks over 1, 5, and 15 minutes. A load of 1.0 on a 1-core CPU indicates 100% capacity.
Job Control: Append `&` to run commands in background; `jobs` lists active jobs; `fg %1` brings job 1 to foreground; `bg %1` resumes job in background.
Batch Mode top: `top -b -n 1` dumps a single non-interactive batch frame ideal for parsing in monitoring scripts.
Syntax Blueprint
command & jobs -l fg %1 bg %1 top -b -n 1 | head -n 15
Use & to run background jobs and top in batch mode (-b) for scriptable metrics.
Core Rules to Remember



Common Beginner Traps & How to Fix Them
Closing the SSH terminal and having background jobs suddenly die.Why it happens: Closing the terminal sends SIGHUP (hangup) signal to all child processes.
How to fix: Run with `nohup command &` or `disown -h` to detach from terminal sessions.
Live Interactive Example
Hit Run Code to see it liveYour Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Run a Background Job and Wait
Run `sleep 1 &` in the background.
Capture PID using `$!` and wait for it with `wait $!`.
Echo "Done waiting".
Finished reading and practicing?
Mark this lesson as completed to update your course progress.