24 Hours of Zero Posts: The 46GB Compressed-Memory Bomb That RSS Couldn't See
Описание и применение
Автоматический скрипт launchd обнаруживает и убивает процессы, потребляющие слишком много памяти, предотвращая тайм‑ауты Playwright и гарантируя непрерывную публикацию в соцсетях.
Задача
Automated social media posting stopped after 24 hours due to hidden memory pressure from compressed pages, causing Playwright to timeout.
Результат
The launchd job automatically detects and kills memory‑hungry background processes, preventing silent crashes and ensuring continuous social media posting.
Рабочий процесс
- 1. Configure launchd to run a shell script every 10 minutes with low priority.
- 2. Use
top -l 1 -n 20 -o mem -stats pid,command,mem,cmprsto fetch MEM and CMPRS values. - 3. Convert human‑readable memory units to MB with a
to_mb()function. - 4. If MEM or CMPRS exceeds thresholds, kill the process with
sudo -n killall <process>and allow launchd to restart it. - 5. For
iii, send SIGTERM, wait, then SIGKILL and runkickstart -kto clean orphaned memory. - 6. Run a separate CPU scan with
ps -Aco pid, %cpu, commto detect high CPU usage; restart if threshold sustained. - 7. Log actions, enforce a 30‑minute cooldown per process, and send a Discord notification with current swap usage.
- 8. Use
shlockto prevent concurrent script executions. - 9. Exclude critical system processes via a
NEVER_TOUCHlist. - 10. Tune thresholds via environment variables in the launchd plist.
Доказательства
dasd: MEM=47G/CMPRS=46G → 閾値3072MB超
killall iii → launchd immediately restart the parent process (node)
- Дата записи: 2026-09-08T22:01:36.259Z