(pid: number, force: boolean = false)
| 48 | } |
| 49 | |
| 50 | export async function killProcess(pid: number, force: boolean = false): Promise<boolean> { |
| 51 | if (!Number.isFinite(pid) || pid <= 0) { |
| 52 | return false; |
| 53 | } |
| 54 | |
| 55 | if (isWindows()) { |
| 56 | return killProcessWindows(pid, force); |
| 57 | } |
| 58 | |
| 59 | try { |
| 60 | process.kill(pid, force ? 'SIGKILL' : 'SIGTERM'); |
| 61 | await waitForProcessToDie(pid, force); |
| 62 | return true; |
| 63 | } catch { |
| 64 | return false; |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Recursively collects all descendant PIDs of a process (depth-first). |
no test coverage detected