* Kills a process by PID * @param pid The PID of the process to kill * @param signal The signal to send to the process
(pid: number, signal: NodeJS.Signals)
| 261 | * @param signal The signal to send to the process |
| 262 | */ |
| 263 | async function killProcess(pid: number, signal: NodeJS.Signals): Promise<void> { |
| 264 | if (process.platform === 'win32') { |
| 265 | // /T kills child processes, /F forces it |
| 266 | await new Promise<void>((resolve) => { |
| 267 | child_process.exec(`taskkill /pid ${pid} /T /F`, () => resolve()); |
| 268 | }); |
| 269 | } else { |
| 270 | // Use -pid to signal the entire process group |
| 271 | try { |
| 272 | process.kill(-pid, signal); |
| 273 | } catch (error) { |
| 274 | assertIsError(error); |
| 275 | if (error.code !== 'ESRCH') { |
| 276 | throw error; |
| 277 | } |
| 278 | } |
| 279 | } |
| 280 | } |
| 281 | |
| 282 | /** |
| 283 | * Kills all tracked processes |
no test coverage detected