RediWM is a Wayland compositor written in Zig (OpenGL ES) that includes everything in one process
System Monitor
proc.zig,collector.zig,model.zigandactions.zighave no compositor or UI dependencies. IPC reuses the stat reader but keeps its window-only, request-driven sampling contract.proc.zigis the interface to the OS. The record types and arithmetic areproc_common.zig; one backend reads them:proc_linux.zig(/proc, aProcessholds the/proc/<pid>directory open) orproc_freebsd.zig(kern.procsysctls; aProcessholds thekinfo_proctaken at open, CPU is in microseconds). Never read/procoutside a backend; a new OS needsProcess,List,cpuTotals,cpuCores,memoryTotals,systemStatsandticksPerSecond. Per-CPU loads pair cores by kernel id, not position (CPUs go offline). Optional footer telemetry lives inproc_linux_system.zig; rates reset with the worker generation. CPU and GPU temperatures stay separate; GPU hwmon reads only the die/package channel. Optional NVIDIA NVML (proc_gpu.zig) is owned by the active worker, released on pause/minimize and shutdown, and never starts a subprocess. The Linux parsers are pure and tested everywhere throughproc_linux.zig.descendantsalso supplies the supervisor's teardown tree: Linux walks task children; FreeBSD follows parent links in onekern.procsnapshot. Its start stamps must match after a kqueue handle opens, before signaling.- A snapshot owns its arena. The worker publishes under its mutex through an eventfd; the UI takes ownership. A generation change cancels enumeration and publication, resets CPU baselines, and wakes the worker. Inactive workers block indefinitely. Never use NSS lookups here: a stalled account service would prevent joining the worker. Local passwd names fall back to numeric UIDs.
- Selections and confirmations own PID + start time, never row indices. Every
action opens a pidfd first, checks the proc identity, UIDs and protected exe,
verifies the pidfd's fdinfo identity and liveness, then signals that fd.
Never fall back to
kill(pid). Tests signal only disposable fixtures. - The CPU/RAM cards and the expanded card's collapse button are shared
widgets (
App.cards) thatapp_summary.layoutplaces over hand-painted cards; visible cards toggle expansion, and the hidden card has no size to hit. Expansion is applied after dispatch (card_request) and easescard_t. App.ensureWidgetsruns after App has a stable address. Widget trees persist across snapshots so focus, presses and field strings survive. Callbacks set pending actions; modal tree changes happen after dispatch returns.- Minimize suspension comes from xdg-shell v6, not keyboard focus. Restore respects Pause. The client uses released shm buffers and fractional-scale + viewporter; theme watches remain live while sampling is stopped.
- Tests:
zig build test-monitor,python3 tests/system_monitor.py, and the latter withREDIWM_TEST_SCALE=1.5. User documentation:docs/system-monitor.md.