Compare commits
No commits in common. "37dc1b173216ae98a72aece3945f3e443fd1047e" and "8c86c852e57da1c116b16d4b535bd556bcc16d5d" have entirely different histories.
37dc1b1732
...
8c86c852e5
24
src/run.ts
24
src/run.ts
|
|
@ -28,28 +28,6 @@ type RunOptions = {
|
||||||
onCommand?: (cmd: Command) => void
|
onCommand?: (cmd: Command) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
function killTree(pid: number): void {
|
|
||||||
// Find any processes that escaped the process group (e.g. via setsid).
|
|
||||||
// This assumes pid === pgid, which holds because the child is spawned
|
|
||||||
// with detached: true (making it a process group leader).
|
|
||||||
try {
|
|
||||||
const result = Bun.spawnSync(["ps", "-eo", "pid,pgid"])
|
|
||||||
const output = result.stdout.toString()
|
|
||||||
const pgid = String(pid)
|
|
||||||
for (const line of output.split("\n")) {
|
|
||||||
const parts = line.trim().split(/\s+/)
|
|
||||||
if (parts[1] === pgid) {
|
|
||||||
const p = parseInt(parts[0]!, 10)
|
|
||||||
if (!isNaN(p) && p !== pid && p > 1) {
|
|
||||||
try { process.kill(p, "SIGKILL") } catch {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch {}
|
|
||||||
// Kill the process group
|
|
||||||
try { process.kill(-pid, "SIGKILL") } catch {}
|
|
||||||
}
|
|
||||||
|
|
||||||
const SENTINEL_PREFIX = "__SHOUT_SENTINEL_"
|
const SENTINEL_PREFIX = "__SHOUT_SENTINEL_"
|
||||||
const VERBOSE_MARKER = "__SHOUT_CMD_"
|
const VERBOSE_MARKER = "__SHOUT_CMD_"
|
||||||
|
|
||||||
|
|
@ -257,7 +235,7 @@ export async function runFile(
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
if (proc.pid) {
|
if (proc.pid) {
|
||||||
killTree(proc.pid)
|
try { process.kill(-proc.pid, "SIGKILL") } catch {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user