1 unstable release
Uses new Rust 2024
| 0.1.0 | Feb 15, 2026 |
|---|
#42 in macOS and iOS APIs
11KB
207 lines
reap
Watch a process and kill child processes when it dies.
On macOS, when a parent process exits, its child processes are reparented to launchd and keep running. reap solves this by monitoring a specified process via kqueue and terminating the child process group when it exits.
Usage
reap [--watch <pid>] -- <command> [args...]
By default, reap watches its own parent process. Use --watch <pid> to watch an arbitrary process.
Example: sketchybar
In sketchybar's config script (sketchybarrc), background processes outlive sketchybar because the shell script exits immediately. Use $PPID (which is sketchybar's PID from the script's perspective) to watch sketchybar:
reap --watch $PPID -- ./plugin.sh &
When sketchybar exits, reap kills plugin.sh and its descendants.
How it works
- Spawns the child command in a new process group
- Monitors the watched PID using kqueue
EVFILT_PROC+NOTE_EXIT(zero polling overhead) - Forwards
SIGTERM/SIGINTto the child process group - When the watched process exits: sends
SIGTERMto the child group, waits up to 5 seconds, then escalates toSIGKILL - Propagates the child's exit code (or
128 + signalif killed by a signal)
Installation
cargo install reap-process
Building from source
git clone https://github.com/typester/reap.git
cd reap
cargo build --release
Requirements
- macOS (uses kqueue, which has no Linux equivalent for this purpose)
License
MIT
Dependencies
~2.5MB
~52K SLoC