Skip to content

alloc/tree-kill

Repository files navigation

@alloc/tree-kill

Purpose

@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.

Installation

pnpm add @alloc/tree-kill

Quick Example

import { 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");

Exit-Time Fallback

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");
});

Documentation Map

  • Conceptual behavior, platform notes, and rewrite boundaries: docs/context.md
  • Runnable repository example: examples/basic-usage.ts
  • Exact exported signatures: run pnpm build and inspect dist/index.d.mts

About

Fork of node-tree-kill

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors