Project 4: The Process Psychic (Process Inspector)

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.

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 status files: Reading /proc/[pid]/stat or /proc/[pid]/status.
  • Calculating CPU usage: Reading /proc/stat (system wide) and process time to calculate percentages.

Key Concepts

  • Virtual Filesystems: /proc exists 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

  1. Reproduce the simplest happy-path scenario.
  2. Build the smallest working version of the core feature.
  3. Add input validation and error handling.
  4. Add instrumentation/logging to confirm behavior.
  5. 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