Project 4: The Process Psychic (Process Inspector)
A tool similar to
psortopthat lists running processes, their state (Running, Sleeping, Zombie), memory usage, and command line arguments. You will do this by parsing the/procfilesystem directly.
Quick Reference
| Attribute | Value |
|---|---|
| Primary Language | C or Python |
| Alternative Languages | Go |
| Difficulty | Level 2: Intermediate |
| Time Estimate | Weekend |
| Knowledge Area | Linux /proc filesystem |
| Tooling | Linux |
| Prerequisites | File I/O, String parsing. |
What You Will Build
A tool similar to ps or top that lists running processes, their state (Running, Sleeping, Zombie), memory usage, and command line arguments. You will do this by parsing the /proc filesystem directly.
Why It Matters
This project builds core skills that appear repeatedly in real-world systems and tooling.
Core Challenges
- Scanning
/proc: Iterating over numeric directories. - Parsing
statusfiles: Reading/proc/[pid]/stator/proc/[pid]/status. - Calculating CPU usage: Reading
/proc/stat(system wide) and process time to calculate percentages.
Key Concepts
- Virtual Filesystems:
/procexists only in RAM. - Process States:
R(Running),S(Sleeping),Z(Zombie). - UID/GID: Mapping numeric IDs to names.
Real-World Outcome
$ ./myps
PID USER STATE CMD
1 root S /sbin/init
1042 douglas R ./myps
1043 douglas S bash
Implementation Guide
- Reproduce the simplest happy-path scenario.
- Build the smallest working version of the core feature.
- Add input validation and error handling.
- Add instrumentation/logging to confirm behavior.
- Refactor into clean modules with tests.
Milestones
- Milestone 1: Minimal working program that runs end-to-end.
- Milestone 2: Correct outputs for typical inputs.
- Milestone 3: Robust handling of edge cases.
- Milestone 4: Clean structure and documented usage.
Validation Checklist
- Output matches the real-world outcome example
- Handles invalid inputs safely
- Provides clear errors and exit codes
- Repeatable results across runs
References
- Main guide:
LEARN_LINUX_UNIX_INTERNALS_DEEP_DIVE.md - “Linux Kernel Development” by Robert Love