MCPcopy
hub / github.com/Kilo-Org/kilocode / killTree

Function killTree

packages/opencode/src/shell/shell.ts:29–58  ·  view source on GitHub ↗
(proc: ChildProcess, opts?: { exited?: () => boolean })

Source from the content-addressed store, hash-verified

27}
28
29export async function killTree(proc: ChildProcess, opts?: { exited?: () => boolean }): Promise<void> {
30 const pid = proc.pid
31 if (!pid || opts?.exited?.()) return
32
33 if (process.platform === "win32") {
34 await new Promise<void>((resolve) => {
35 const killer = spawn("taskkill", ["/pid", String(pid), "/f", "/t"], {
36 stdio: "ignore",
37 windowsHide: true,
38 })
39 killer.once("exit", () => resolve())
40 killer.once("error", () => resolve())
41 })
42 return
43 }
44
45 try {
46 process.kill(-pid, "SIGTERM")
47 await sleep(SIGKILL_TIMEOUT_MS)
48 if (!opts?.exited?.()) {
49 process.kill(-pid, "SIGKILL")
50 }
51 } catch (_e) {
52 proc.kill("SIGTERM")
53 await sleep(SIGKILL_TIMEOUT_MS)
54 if (!opts?.exited?.()) {
55 proc.kill("SIGKILL")
56 }
57 }
58}
59
60function full(file: string) {
61 if (process.platform !== "win32") return file

Callers

nothing calls this directly

Calls 3

resolveFunction · 0.70
spawnFunction · 0.50
sleepFunction · 0.50

Tested by

no test coverage detected