(pid: number)
| 188 | * Kill a process and all its children (cross-platform) |
| 189 | */ |
| 190 | export function killProcessTree(pid: number): void { |
| 191 | if (process.platform === "win32") { |
| 192 | // Use taskkill on Windows to kill process tree |
| 193 | try { |
| 194 | spawn("taskkill", ["/F", "/T", "/PID", String(pid)], { |
| 195 | stdio: "ignore", |
| 196 | detached: true, |
| 197 | }); |
| 198 | } catch { |
| 199 | // Ignore errors if taskkill fails |
| 200 | } |
| 201 | } else { |
| 202 | // Use SIGKILL on Unix/Linux/Mac |
| 203 | try { |
| 204 | process.kill(-pid, "SIGKILL"); |
| 205 | } catch { |
| 206 | // Fallback to killing just the child if process group kill fails |
| 207 | try { |
| 208 | process.kill(pid, "SIGKILL"); |
| 209 | } catch { |
| 210 | // Process already dead |
| 211 | } |
| 212 | } |
| 213 | } |
| 214 | } |
no test coverage detected