MCPcopy Create free account
hub / github.com/heygen-com/hyperframes / killProcessTree

Function killProcessTree

packages/cli/src/utils/orphanCleanup.ts:40–66  ·  view source on GitHub ↗
(pid: number, signal: NodeJS.Signals = "SIGTERM")

Source from the content-addressed store, hash-verified

38 * the pgrep/ps utilities are not available.
39 */
40export function killProcessTree(pid: number, signal: NodeJS.Signals = "SIGTERM"): void {
41 if (process.platform === "win32") return;
42
43 const descendants = getDescendants(pid);
44 const allPids = [...descendants.reverse(), pid];
45
46 for (const p of allPids) {
47 try {
48 process.kill(p, signal);
49 } catch {
50 // Already exited.
51 }
52 }
53
54 // Escalate to SIGKILL after a short grace period for any survivors.
55 if (signal !== "SIGKILL") {
56 setTimeout(() => {
57 for (const p of allPids) {
58 try {
59 process.kill(p, "SIGKILL");
60 } catch {
61 // Already exited.
62 }
63 }
64 }, 500).unref();
65 }
66}
67
68function getDescendants(pid: number): number[] {
69 let children: number[];

Callers 3

killOrphansByNameFunction · 0.85
shutdownFunction · 0.85

Calls 2

getDescendantsFunction · 0.85
killMethod · 0.80

Tested by

no test coverage detected