22.4 Process Management (ps, top, kill, systemctl) (Week 22 • Linux, Docker, Nginx & CI/CD)
1. What It Is, Why It Is Required & How It Works
Process Management (ps, top, kill, systemctl) (Linux, Docker, Nginx & CI/CD) covers `ps aux`, `top`/`htop`, graceful `SIGTERM` (`kill -15`) vs last-resort `SIGKILL` (`kill -9`), exit codes (`0` vs non-zero), and `systemd` (`systemctl status/restart`, `journalctl -u`). It is required in professional Python backend engineering to Sending `SIGTERM` during rolling deploys so Gunicorn/Uvicorn finishes in-flight HTTP requests before exiting cleanly! Under the hood, understanding its exact execution behavior, memory/query footprint, and edge-case rules allows you to write reliable, maintainable Python, SQL, Django, and FastAPI code instead of fragile trial-and-error snippets.
2. Where It Is Used in Industry
Sending `SIGTERM` during rolling deploys so Gunicorn/Uvicorn finishes in-flight HTTP requests before exiting cleanly!
3. Granular Subtopics Covered
- `ps aux`: Core building block of Process Management (ps, top, kill, systemctl): Sending `SIGTERM` during rolling deploys so Gunicorn/Uvicorn finishes in-flight HTTP requests before exiting cleanly!
- `top`/`htop`: Master how '`top`/`htop`' operates inside Process Management (ps, top, kill, systemctl) so your Python backend handles real inputs and scale predictably.
- Graceful `SIGTERM` (`kill -15`) vs last-resort `SIGKILL` (`kill -9`): Master how 'Graceful `SIGTERM` (`kill -15`) vs last-resort `SIGKILL` (`kill -9`)' operates inside Process Management (ps, top, kill, systemctl) so your Python backend handles real inputs and scale predictably.
- Exit codes (`0` vs non-zero): Master how 'Exit codes (`0` vs non-zero)' operates inside Process Management (ps, top, kill, systemctl) so your Python backend handles real inputs and scale predictably.
- Production Edge-Case & Pitfall Guard (Process Management (ps, top, kill, systemctl)): Prevent common defect: Using `kill -9` (`SIGKILL`) routinely — kills workers mid-transaction without running `finally` or `lifespan` shutdown hooks!
- Hands-On Python Implementation & Verification (Process Management (ps, top, kill, systemctl)): Inspect worker PIDs, test graceful `SIGTERM` drain behavior, and read a `systemd` unit file.
4. Reference Implementation in Python / Backend Stack
# Graceful deploy stop: SIGTERM (finishes in-flight requests) -> timeout -> SIGKILL
5. Common Production Mistakes to Avoid
- Using `kill -9` (`SIGKILL`) routinely — kills workers mid-transaction without running `finally` or `lifespan` shutdown hooks!
- Skipping boundary/None/empty input validation when implementing Process Management (ps, top, kill, systemctl) in Linux, Docker, Nginx & CI/CD.
- Committing untested Process Management (ps, top, kill, systemctl) code without verifying edge cases, structured logs, and time/space impact.
6. Mandatory Hands-On Exercise
Inspect worker PIDs, test graceful `SIGTERM` drain behavior, and read a `systemd` unit file.
7. Technical Interview Checkpoints
- Q: What problem does Process Management (ps, top, kill, systemctl) solve in Linux, Docker, Nginx & CI/CD, and what breaks in production if it is misused?
Key Focus: Sending `SIGTERM` during rolling deploys so Gunicorn/Uvicorn finishes in-flight HTTP requests before exiting cleanly! Avoid common mistake: Using `kill -9` (`SIGKILL`) routinely — kills workers mid-transaction without running `finally` or `lifespan` shutdown hooks! - Q: Walk through the internal working and key mechanics of Process Management (ps, top, kill, systemctl) (`ps aux`, `top`/`htop`, graceful `SIGTERM` (`kill -15`) vs last-resort `SIGKILL` (`kill -9`), exit codes (`0` vs non-zero), and `systemd` (`systemctl status/restart`, `journalctl -u`)).
Key Focus: Explain `ps aux`, `top`/`htop`, graceful `SIGTERM` (`kill -15`) vs last-resort `SIGKILL` (`kill -9`), exit codes (`0` vs non-zero), and `systemd` (`systemctl status/restart`, `journalctl -u`) step-by-step with a concrete Python 3.12 / PostgreSQL / Django / FastAPI example. - Q: How did you implement and test Process Management (ps, top, kill, systemctl) inside your backend module or capstone project?
Key Focus: Reference hands-on implementation: Inspect worker PIDs, test graceful `SIGTERM` drain behavior, and read a `systemd` unit file.