Linux Basics Lesson 24 of 38
The server is glowing
8 minutes
Learning goals
- Find the process behind a CPU alarm by its PID.
- End it with TERM, without hitting anything else.
- Check that the service next to it is still running.
The tools from this module are ready for you, with a few limits on this page. grep is not loaded, so ps aux | grep python gives you command not found here. Instead, use ps aux --sort=-%cpu, which puts the biggest on top, or pgrep -a python3. top and sudo are not loaded either, and they answer with a hint.
Steps
Step 1/3: Find the process that is eating the CPU, and note its PID. Step 2/3: End it politely. The report (3021) and the app (2114) keep running. Step 3/3: Now make sure that the app is still all right. Its main process should still be 2114. Scenario solved
Monitoring alarm: The CPU on web-01 has been at 100 % for 20 minutes, and the API is answering slowly. You log in. Find the culprit and get rid of it, and do not take anything else down with it.
-
Step 1 done solved before
Find the process that is eating the CPU, and note its PID.
Hint 1: ps without options only shows your own terminal. You need all processes, the biggest first.Hint 2: Type ps aux --sort=-%cpuSolution
ps aux --sort=-%cpuWhy: 397 % means nearly four cores for one program. ps cuts it to python3 expor at 80 characters, and pgrep -a python3 shows the full line: python3 export.py. Three Python processes run here, so you need the PID and not the name.
See the solution? You get fewer XP for this scenario.
Start over? The whole scenario goes back to step 1. Your hints stay, XP only comes once.
-
Step 2 done solved before
End it politely. The report (3021) and the app (2114) keep running.
Hint 1: You know the PID. Which command sends the signal, and which signal does it send by default?Hint 2: Type kill 4711Solution
kill 4711Why: TERM gives export.py the chance to close its files. Only if it were still there after a few seconds would kill -9 have its turn, and whoever starts with that destroys what the investigation would need. Why it ran away is the next question, once the fire is out.
See the solution? You get fewer XP for this scenario.
Start over? The whole scenario goes back to step 1. Your hints stay, XP only comes once.
-
Step 3 done solved before
Now make sure that the app is still all right. Its main process should still be 2114.
Hint 1: You want the service and its main PID. Type systemctl status app.Hint 2: Type systemctl status appSolution
systemctl status appWhy: The same PID as before means it never restarted, and the alarm should now go quiet. Had the main process been the problem, the clean way would have been sudo systemctl restart app, not kill, so that systemd knows what is going on.
See the solution? You get fewer XP for this scenario.
Start over? The whole scenario goes back to step 1. Your hints stay, XP only comes once.
Scenario solved
Why each step mattered
- Step 1: 397 % means nearly four cores for one program. ps cuts it to python3 expor at 80 characters, and pgrep -a python3 shows the full line: python3 export.py. Three Python processes run here, so you need the PID and not the name.
- Step 2: TERM gives export.py the chance to close its files. Only if it were still there after a few seconds would kill -9 have its turn, and whoever starts with that destroys what the investigation would need. Why it ran away is the next question, once the fire is out.
- Step 3: The same PID as before means it never restarted, and the alarm should now go quiet. Had the main process been the problem, the clean way would have been sudo systemctl restart app, not kill, so that systemd knows what is going on.
Start over? The whole scenario goes back to step 1. Your hints stay, XP only comes once.
Loading terminal …
Esc, then Tab leaves the terminal
Step 1 of 3
Cards
-
Card 1 of 2
Tap the card or press Space to turn it over.
-
Card 2 of 2
Tap the card or press Space to turn it over.
Cheat sheet
The most important command lines of this module on one A4 page, black and white, to print or keep on your phone.
- Download PDF (PDF, 19 KB)
- View as image (PNG, 57 KB)