(pid: number, force: boolean)
| 17 | } |
| 18 | |
| 19 | function killProcessWindows(pid: number, force: boolean): boolean { |
| 20 | if (!isProcessAlive(pid)) { |
| 21 | return true; |
| 22 | } |
| 23 | |
| 24 | const args = ['/T', '/PID', pid.toString()]; |
| 25 | if (force) { |
| 26 | args.unshift('/F'); |
| 27 | } |
| 28 | try { |
| 29 | const result = spawn.sync('taskkill', args, { |
| 30 | stdio: 'pipe', |
| 31 | windowsHide: true |
| 32 | }); |
| 33 | if (result.error) { |
| 34 | return false; |
| 35 | } |
| 36 | |
| 37 | if (result.status === 0) { |
| 38 | return true; |
| 39 | } |
| 40 | |
| 41 | // Process teardown on Windows is racy: by the time taskkill runs, the target |
| 42 | // may already be gone, which commonly surfaces as non-zero exit codes |
| 43 | // (including 128 in some shells). Treat this as success if PID is no longer alive. |
| 44 | return !isProcessAlive(pid); |
| 45 | } catch { |
| 46 | return false; |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | export async function killProcess(pid: number, force: boolean = false): Promise<boolean> { |
| 51 | if (!Number.isFinite(pid) || pid <= 0) { |
no test coverage detected