filedog is a subprocess watchdog keyed on a watch file’s latest activity timestamp: Unix stat atime, mtime, and ctime—idle time is measured from max(atime, mtime, ctime). When idle exceeds a threshold, the child is killed and optionally restarted after a cooldown. Useful when liveness should follow an external heartbeat file (e.g. client-side fuzzing, long-running workers).
Platforms: Unix only (Linux, *BSD, macOS, …). Building for non-Unix targets fails by design.
Languages: 简体中文
- Spawns the command in its own session (
setsid) with a dedicated process group so the whole tree can be signalled. - Polls the watch file: if
now - max(atime, mtime, ctime) >= --timeout, treats as idle—sendsSIGTERMto the process group, waits, thenSIGKILLif needed; after--delay, may respawn. - After each spawn, a
--waitgrace period runs (only exit detection, no idle logic). With--wait 0, a short ~200ms poll still runs to avoid anexecrace where the child is mistaken for hung. --retrylimits consecutive idle kills; a poll that sees fresh activity resets the counter.- On
SIGTERM/SIGINT/SIGHUP, filedog kills the child process group and exits with128 + signal number. - The watch file is created if missing (parent dirs created as needed). It must be a regular file, not a directory.
- Rust (stable recommended;
edition = "2021")
cargo build --releaseBinary: target/release/filedog. Install from the repo root:
cargo install --path .(Ensure your Cargo bin directory is on PATH.)
filedog -f <watch-file> [options] -- <command> [args...]
If the command starts with -, put -- before it.
# Watch .dog: 10s grace after start; 30s idle threshold; 5s cooldown before respawn; --retry 3
filedog -f .dog -w 10 -d 5 -t 30 -r 3 -- ./your-command arg1 arg2
filedog --file .dog --wait 10 --delay 5 --timeout 30 --retry 3 -- ./your-command arg1 arg2Full CLI details:
cargo run -- --help
# or
./target/release/filedog --help| Option | Description |
|---|---|
-f, --file PATH |
Watch file (required). Idle uses max(atime, mtime, ctime). |
-w, --wait SEC |
Grace after each child start (seconds). Default 0 (still includes a short exec race window). |
-d, --delay SEC |
Sleep after an idle kill before respawning. Default 0. |
-t, --timeout SEC |
Idle threshold and poll interval (seconds). Default 30. Must be > 0. |
-r, --retry N |
Max consecutive idle-kill counter before exit 124; reset when a poll sees the watch file “active”. With N=0, exit after the first idle kill (no respawn). |
--no-banner |
Suppress short red stderr lines on idle-driven restarts. |
--debug |
Red stderr logs for [wait] / [delay] / [check]. |
Many systems mount with relatime, so atime may not update on every read. If you rely on read access to refresh idle time, consider:
- Mounting with
strictatime, or - Avoiding
O_NOATIMEon the watch path, or - Leaning on mtime/ctime (e.g. periodic
touchor writes by the worker).
See in-source comments and NOTES in filedog --help.
| Situation | Code |
|---|---|
| Usage/validation errors, fatal spawn/stat failures | 2 |
Idle kills exceeded --retry |
124 |
| Child exits on its own | Child exit code (or 128 + signal on Unix if killed by signal) |
filedog stopped by SIGTERM / SIGINT / SIGHUP |
128 + signal number |
clap— CLI parsinglibc— process groups,kill,setsid, …signal-hook— async signal handling