$ show htop-dev/htop
htop is a cross-platform interactive process viewer and system monitor written in C on ncurses. It enumerates and displays processes by reading OS kernel interfaces — primarily /proc on Linux, sysctl/kvm/kstat on the BSDs and Solaris, libproc/mach on macOS, and PCP (Performance Co-Pilot) metrics for the pcp-htop variant — and renders a scrollable process table alongside a header of pluggable meters (CPU, memory, swap, disk I/O, network I/O, ZFS ARC, GPU utilization, pressure stall, battery, sensors, and more). Beyond display, it supports process management actions: kill, renice, set CPU affinity, scheduling and I/O priority, spawning strace/lsof child processes, plus tree view, sorting, filtering, incremental search, and persistent configuration in htoprc. Architecturally this is a monolithic C application with emulated object orientation: an Object base class with vtable-style Class function tables, generic containers (Hashtable with Robin Hood open addressing, Vector with ownership semantics), a RichString wide-character rendering layer, reusable Panel/Meter widget classes, and a ScreenManager event loop. Each supported OS lives in a backend directory (linux/, darwin/, freebsd/, openbsd/, netbsd/, dragonflybsd/, solaris/, pcp/, unsupported/) that implements the Platform/Machine/ProcessTable/Process contract. Entry points are htop.c and pcp-htop.c, which route through CommandLine_run() into ScreenManager_run(). The build uses GNU autotools with optional features (hwloc, libsensors, libnl, libcap, libunwind, PCP), and CI runs the binary headlessly under sanitizers plus a Lua/rote terminal-emulation test suite. Maintenance is genuinely active: recent commits, a CodeQL workflow, address/UB sanitizer jobs, valgrind suppressions, and a ChangeLog showing security fixes (CVE-2024-37676) and steady feature work through 3.6.0-dev. The honest caveats are platform fragility: Solaris and OpenBSD have TODO stubs for disk/network I/O, NetBSD uses deprecated proplib compatibility aliases, /proc and DRM fdinfo parsers are sensitive to kernel format changes, and there is visible copy-paste divergence across BSD backend field arrays. The core Linux path is current and well-maintained; the tail platforms lag, which keeps overall technical drift at medium rather than low.
The LLM identified 6 files worth highlighting for reuse:
A generic hash table using Robin Hood open addressing with tombstone deletion and linear probing. Implements safe iteration over live entries, key-hash chaining, and runtime invariant validation under !NDEBUG. It is nearly dependency-free (only the project's allocation wrappers) and can be lifted into any C project needing a compact, high-performance map without external dependencies.
A generic dynamic array with explicit ownership semantics (borrowed vs. owned items), amortized growth, bulk-insertion, compaction that preserves order, and a hybrid quicksort/insertion-sort for sorted insertion. Includes useful primitives like remove/insert with object lifecycle handling and validation checks. Self-contained and directly reusable as a generic C container.
Hardened memory and string utilities: overflow-checked xMalloc/xCalloc/xRealloc/xReallocArray wrappers, safe string copy/append with explicit bounds, whitespace trimming, token extraction, case-insensitive word matching, and read_at() for loop-until-complete file reads. Represents a disciplined, portable pattern for C memory safety and is trivially extractable into any new C project.
A persistent search-history store demonstrating an exemplary secure file-I/O pattern: opens with O_NOFOLLOW|O_NONBLOCK, fstat-verifies regular-file type and ownership, refuses symlinks, falls back to read-only when unwritable, and writes back safely. The hardening technique (verify before read, atomic replace on write) is a reusable recipe for any C program persisting user-configurable data.
A wide-character-aware formatted string buffer with per-character attribute tracking for curses rendering. Handles multi-byte characters, combining marks, a newline-in-string mode, and an ASCII fallback when wide-char support is absent. Demonstrates non-obvious terminal-rendering craftsmanship and can be extracted for any curses-based tool needing safe Unicode output.
Loads a C++ demangler (__cxa_demangle) at runtime from libstdc++, libc++, or libcxxrt via dlopen, avoiding any link-time dependency on a specific C++ runtime. Periodically re-attempts loading after a failed library guard, returning the original mangled name on any failure. A clean, defensive dynamic-loading pattern for optional capability detection in C programs.