(pid: number)
| 140 | } |
| 141 | |
| 142 | export function isProcessAlive(pid: number): boolean { |
| 143 | if (!pid || pid <= 0) return false; |
| 144 | try { |
| 145 | process.kill(pid, 0); |
| 146 | return true; |
| 147 | } catch (e: unknown) { |
| 148 | // EPERM means it exists, we just can't signal it. ESRCH means it's gone. |
| 149 | const code = (e as NodeJS.ErrnoException | undefined)?.code; |
| 150 | return code === "EPERM"; |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | /** |
| 155 | * Read the cmdline of a running process. Returns "" on any error. |
no outgoing calls