@alloc/tree-kill kills a spawned process and its descendants across macOS,
Linux, and Windows.
It is a rewrite of the original
tree-kill package that preserves
the same OS-specific traversal strategy but changes the public API to a
ProcessLike interface with separate async and sync entrypoints instead of a
raw pid plus callback.
pnpm add @alloc/tree-killimport { spawn } from "node:child_process";
import treeKill from "@alloc/tree-kill";
const child = spawn(process.execPath, ["-e", "setInterval(() => {}, 1000)"], {
stdio: "ignore",
});
await treeKill(child, "SIGTERM");Use the synchronous export only in shutdown paths where async work cannot be
awaited reliably, such as process.on("exit"):
import { spawn } from "node:child_process";
import treeKill, { treeKillSync } from "@alloc/tree-kill";
const child = spawn(process.execPath, ["-e", "setInterval(() => {}, 1000)"], {
stdio: "ignore",
});
await treeKill(child, "SIGTERM");
process.on("exit", () => {
treeKillSync(child, "SIGTERM");
});- Conceptual behavior, platform notes, and rewrite boundaries: docs/context.md
- Runnable repository example: examples/basic-usage.ts
- Exact exported signatures: run
pnpm buildand inspectdist/index.d.mts