| 4 | let isWindows = process.platform === "win32"; |
| 5 | |
| 6 | export const kill = async (pid: number) => { |
| 7 | if (!isAlive(pid)) {return;} |
| 8 | if (isWindows) { |
| 9 | await execa("taskkill", ["/F", "/PID", pid.toString()]).catch((error: any) => { |
| 10 | // taskkill 128 -> the process is already dead |
| 11 | if (error.exitCode === 128) {return;} |
| 12 | if (/There is no running instance of the task./.test(error.message)) {return;} |
| 13 | console.warn(error.message); |
| 14 | }); |
| 15 | return; |
| 16 | } |
| 17 | await execa("kill", ["-9", pid.toString()]).catch((error: any) => { |
| 18 | // process is already dead |
| 19 | if (/No such process/.test(error.message)) {return;} |
| 20 | console.warn(error.message); |
| 21 | }); |
| 22 | }; |
| 23 | |
| 24 | let isAlive = (pid: number) => { |
| 25 | try { |