MCPcopy Index your code
hub / github.com/coder/mux / killProcessTree

Function killProcessTree

src/node/utils/disposableExec.ts:31–61  ·  view source on GitHub ↗
(pid: number)

Source from the content-addressed store, hash-verified

29}
30
31export function killProcessTree(pid: number): void {
32 if (!Number.isFinite(pid) || pid <= 0) {
33 return;
34 }
35
36 // process.kill(-pid) is Unix-only; on Windows we must use taskkill to kill the full tree.
37 if (process.platform === "win32") {
38 try {
39 execFileSync("taskkill", ["/PID", String(pid), "/T", "/F"], {
40 stdio: "ignore",
41 windowsHide: true,
42 });
43 } catch {
44 // Ignore errors - process may already have exited.
45 }
46
47 return;
48 }
49
50 // Prefer killing the entire process group. This requires the target process to be a group leader.
51 try {
52 process.kill(-pid, "SIGKILL");
53 } catch {
54 // Fall back to just the individual process.
55 try {
56 process.kill(pid, "SIGKILL");
57 } catch {
58 // ignore
59 }
60 }
61}
62
63/**
64 * Disposable wrapper for child processes that ensures immediate cleanup.

Callers 5

terminateCloneProcessMethod · 0.90
execFunction · 0.90
onAbortFunction · 0.90
execMethod · 0.90
[Symbol.dispose]Method · 0.85

Calls 1

killMethod · 0.65

Tested by

no test coverage detected