8 Fake ps Lines and One bash 3.2 Trap: Reaping Orphaned Chrome Without Killing the Browser You're Using
Описание и применение
Скрипт безопасно убивает только орфанные процессы Chrome, используя allowlist по пути и каталогу пользовательских данных, и проверяется через фиктивный вывод ps, чтобы не завершать активный браузер.
Задача
Determining whether a Chrome process is an orphan that can be safely killed versus a process currently in use, using only a single line of ps output, which can lead to accidental termination of the user's active Chrome session.
Результат
The script safely reaps only intended Chrome orphans by using an allowlist based on executable path and user-data-dir, and by testing with a ps fixture, preventing accidental termination of the user's active Chrome.
Рабочий процесс
- Identify criteria: parent pid=1 (launchd), process age > threshold, and verify the process is an automation Chrome via allowlist
- Implement allowlist function is_target_process that checks command_line for specific executable paths and requires --user-data-dir under ~/dev/, rejecting known safe profiles
- Modify the script to use a variable PS_BIN that can be overridden by CHROME_REAPER_PS_BIN for testing
- Create a fixture script that outputs simulated ps output to inject custom process lists without launching real processes
- Run the script with the fixture to verify only intended orphans are killed
- Deploy the script via launchd to execute every 30 minutes
Доказательства
if the targeting is off, it will also take out the Chrome window I'm browsing in right now
never decide based on the executable path alone
- Дата записи: 2026-09-15T14:30:56.628Z