(pid: number)
| 63 | } |
| 64 | |
| 65 | function isProcessAlive(pid: number): boolean { |
| 66 | if (!Number.isInteger(pid) || pid <= 0) { |
| 67 | return false; |
| 68 | } |
| 69 | try { |
| 70 | // 0 is a signal to check if the process is alive. |
| 71 | process.kill(pid, 0); |
| 72 | return true; |
| 73 | } catch (e: unknown) { |
| 74 | const err = e as NodeJS.ErrnoException; |
| 75 | // ESRCH = no such process |
| 76 | if (err.code === 'ESRCH') { |
| 77 | return false; |
| 78 | } |
| 79 | // EPERM = operation not permitted (e.g. process is running for our perspective) |
| 80 | if (err.code === 'EPERM') { |
| 81 | return true; |
| 82 | } |
| 83 | return false; |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * Releases the events lock if the current process is the holder. |
no outgoing calls
no test coverage detected