Project 2: A top-like Process Viewer with Ncurses
A read-only, auto-refreshing dashboard that lists running processes, their PIDs, CPU usage, and memory usage, similar to the classic
toporhtopcommands.
Quick Reference
| Attribute | Value |
|---|---|
| Primary Language | C |
| Alternative Languages | Python (with curses module), Rust (with ncurses-rs) |
| Difficulty | Level 2: Intermediate |
| Time Estimate | 1-2 weeks |
| Knowledge Area | TUI / Systems Programming |
| Tooling | ncurses library, /proc filesystem on Linux |
| Prerequisites | Project 1 (optional but helpful), solid C programming skills, basic understanding of Linux processes. |
What You Will Build
A read-only, auto-refreshing dashboard that lists running processes, their PIDs, CPU usage, and memory usage, similar to the classic top or htop commands.
Why It Matters
This project builds core skills that appear repeatedly in real-world systems and tooling.
Core Challenges
- Initializing and cleaning up ncurses → maps to managing the ncurses lifecycle
- Creating a non-blocking main loop → maps to updating the UI without waiting for user input
- Reading and parsing
/procfilesystem → maps to fetching the data to display - Formatting data into aligned columns → maps to controlling screen layout precisely
Key Concepts
- Ncurses Windows: “NCURSES Programming HOWTO” - Pradeep Padala
- Non-blocking Input: Setting
nodelay(stdscr, TRUE)and a timeout. - /proc/[pid]/stat & /proc/[pid]/status:
man procfor the format of these files. - Formatted Printing: Using
mvprintwandattron/attrofffor colors and styles.
Real-World Outcome
(Terminal Output)
MyTop - 14:05:21 | Tasks: 123, 1 running | Uptime: 5 days
CPU: [■■■□□□□□□□□□□□□□□□□□] 15.0% | Mem: [■■■■■■■■■□□□□□□□□□□□] 45.2%
PID USER CPU% MEM% COMMAND
1234 root 12.5 2.3 ./my-app
5678 douglas 2.1 5.8 chrome
9101 douglas 0.5 1.2 zsh
1121 root 0.2 0.8 systemd
...
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_TUI_PROGRAMMING_PROJECTS.md - “The Linux Programming Interface” by Michael Kerrisk