`process.kill(pid, 0)` probe — true if the pid exists, false on ESRCH.
(pid: number)
| 112 | |
| 113 | /** `process.kill(pid, 0)` probe — true if the pid exists, false on ESRCH. */ |
| 114 | function pidAlive(pid: number): boolean { |
| 115 | try { |
| 116 | process.kill(pid, 0); |
| 117 | return true; |
| 118 | } catch (err) { |
| 119 | const code = (err as NodeJS.ErrnoException).code; |
| 120 | if (code === 'ESRCH') return false; |
| 121 | // EPERM = process exists but we can't signal it (different user). Treat as alive. |
| 122 | if (code === 'EPERM') return true; |
| 123 | // Anything else: be safe, assume alive so we don't clobber. |
| 124 | return true; |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | /** Read + JSON.parse the lock file; returns undefined on any error so callers can fall through. */ |
| 129 | function readLockContents(path: string): LockContents | undefined { |
no test coverage detected