← ClaudeAtlas

zero-cpu-daemon-skilllisted

Event-driven Linux daemon architecture with 0% standby CPU load via inotifywait, fortified with 9 physical circuit fuses, kernel watch limit tuning, and debounce handling.
4ntiDandruff/zero-bloat-skills · ★ 1 · AI & Automation · score 74
Install: claude install-skill 4ntiDandruff/zero-bloat-skills
# Zero-CPU Linux Inotify Daemons Skill Event-driven Linux background daemon design built with POSIX shell and `inotifywait`. Leverages native OS kernel filesystem notifications to maintain 0.0% CPU utilization while idle, eliminating resource-draining polling loops and kernel table overflows. --- ## 1. Event-Driven vs Polling Loop Comparison - **Traditional Polling Loop**: `while true; do check_files; sleep 2; done` Generates continuous context switches, drains battery power, and introduces response latency. - **Zero-CPU Inotify Daemon**: Process sleeps in kernel state (`TASK_INTERRUPTIBLE`). Only when the kernel dispatches `close_write` or `moved_to` events does the daemon awaken, completing actions in <0.1s. --- ## 2. Kernel Inotify Limits Pre-Flight Check When monitoring deep directory trees, default Linux kernel limits (`8192` watches) can trigger fatal `No space left on device` errors: ```bash # Check current system watch allocation cat /proc/sys/fs/inotify/max_user_watches # Permanent production elevation (up to 524,288 directories): echo "fs.inotify.max_user_watches=524288" | sudo tee /etc/sysctl.d/99-inotify.conf sudo sysctl --system ``` --- ## 3. 9 Circuit Safety Fuses Implementation ```bash #!/usr/bin/env bash set -euo pipefail WATCH_DIR="$HOME/Downloads" # Ensure target directory exists before attaching watch mkdir -p "$WATCH_DIR" inotifywait -m -e close_write,moved_to --format "%w%f" "$WATCH_DIR" | while read -r FILE_PATH; do # Fuse 1: Phy