Practice & Assessment
Test your understanding of Process Management & System Monitoring
Multiple Choice Questions
5What is the difference between SIGTERM and SIGKILL?
A process shows in `ps aux` output but `df -h` shows the disk is still 100% full after deleting its log file. What is the most likely cause?
What does `nohup ./script.sh > output.log 2>&1 &` accomplish?
What does load average of 8.0 on a 4-core machine indicate?
What happens to a background job when you close the terminal that started it?
Coding Challenges
1Process Monitor Script
Write a script monitor.sh that accepts a process name as $1 (e.g. nginx or python3). The script must: (1) Check if the process is running using pgrep, print 'RUNNING' or 'NOT RUNNING' with the PID count, (2) If running, display its CPU and memory usage using ps -p with the PIDs found by pgrep, (3) If the process is using more than 50% CPU (check with ps aux and awk), print a WARNING, (4) Accept a second argument -k that kills the process with SIGTERM if passed, (5) Set up a trap to print a summary message on exit. Test with ./monitor.sh nginx and ./monitor.sh nginx -k. Expected: process status printed, warning shown if high CPU, kill works cleanly. Time estimate: 20 minutes.
Mini Project
System Resource Dashboard Script
Build an interactive terminal dashboard script dashboard.sh that refreshes every 5 seconds (use a while true loop with sleep 5) and displays: (1) Current date/time header, (2) Uptime and load averages from uptime, (3) Memory usage with a simple text progress bar (e.g. [==== ] 55%) calculated from free -m output using awk, (4) Disk usage of / with percentage from df -h /, (5) Top 3 CPU-consuming processes from ps aux, (6) Whether a configurable list of services (defined as an array at the top of the script) are running via pgrep. Use clear before each refresh so it appears to update in place. Pressing Ctrl+C should trigger a trap that prints 'Dashboard stopped' and exits cleanly. Parameterize the refresh interval as $1 with a default of 5.
