A lightweight system monitor daemon for macOS on Apple Silicon (M-series). Written in C11, it continuously polls thermal pressure and CPU load using native macOS APIs, logs timestamped stats to a file, and fires a system notification when pressure thresholds are exceeded.
- Polls
vm.pressure_levelviasysctlbynamefor real-time thermal pressure - Calculates total CPU usage across all cores using
mach_host_self()andhost_processor_info - Appends timestamped entries to
~/Library/Logs/m4_sentinel.log - Triggers a native macOS notification when thermal pressure exceeds the threshold
- Runs silently in the background with
--daemonmode (usesfork()+setsid()) - Proper error handling for all Mach service calls
- Built with CoreFoundation and IOKit via a simple Makefile
- macOS 13+ on Apple Silicon (M1/M2/M3/M4)
- Xcode Command Line Tools (
xcode-select --install)
git clone https://github.com/chakri192/m4-sentinel.git
cd m4-sentinel
makeThis compiles sentinel.c and links CoreFoundation + IOKit, producing a sentinel binary.
./sentinelUseful for testing — logs and alerts print to stdout alongside the log file.
./sentinel --daemonThe process detaches from the terminal using fork() and setsid(). Logs continue writing to:
~/Library/Logs/m4_sentinel.log
pkill sentinelOr find the PID and kill it manually:
pgrep sentinel
kill <PID>Each log entry looks like:
[2025-07-01 08:42:31] thermal_pressure=0 cpu_load=34.7%
[2025-07-01 08:42:41] thermal_pressure=1 cpu_load=78.2% ⚠ ALERT SENT
Logs are appended — they persist across runs. Rotate manually if needed:
: > ~/Library/Logs/m4_sentinel.log # clear the log| Component | API Used |
|---|---|
| Thermal pressure | sysctlbyname("kern.memorystatus_level", ...) |
| CPU load | host_processor_info(mach_host_self(), ...) |
| Notifications | osascript / CoreFoundation alert |
| Daemon mode | POSIX fork() + setsid() |
| Build system | Makefile linking -framework CoreFoundation -framework IOKit |
m4-sentinel/
├── sentinel.c # Core monitor logic
├── Makefile # Build and link instructions
├── .gitignore
└── README.md
Documentation assisted by local LLMs via Ollama:
| Model | Used for |
|---|---|
qwen2.5-coder:7b |
Code suggestions, refactoring |
llama3.1:8b |
Prose, documentation, commit messages |