Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

8 Fake ps Lines and One bash 3.2 Trap: Reaping Orphaned Chrome Without Killing the Browser You're Using

Description and use

The script safely kills only intended Chrome orphans by using an allowlist based on executable path and user-data-dir, and is tested with a ps fixture to avoid terminating the user's active Chrome.

Problem

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.

Outcome

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.

Workflow

  • 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

Evidence

if the targeting is off, it will also take out the Chrome window I'm browsing in right now

Source

never decide based on the executable path alone

Source

  • Record date: 2026-09-15T14:30:56.628Z