Commit b117282
Verify primary PID is still alive before assuming it is running (#217)
When a primary instance is force-killed (SIGKILL), the shared memory
block persists on Unix systems with `primary=true` and the stale PID.
Currently this causes all subsequent launches to detect a non-existent
primary and immediately exit as secondary instances.
This PR adds an `isProcessRunning()` check after the shared memory
checksum verification. If the recorded `primaryPid` no longer
corresponds to a running process:
- **Unix**: uses `kill(pid, 0)` + `errno != ESRCH`
- **Windows**: uses `OpenProcess()` + `GetExitCodeProcess()`
The new instance then takes over as primary instead of exiting.
Tested on macOS (force-kill scenario) and confirmed the stale PID
warning is now followed by successful takeover.
Co-authored-by: Itay Grudev <itay+git2020@grudev.com>1 parent d08e923 commit b117282
1 file changed
Lines changed: 34 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
29 | 37 | | |
30 | 38 | | |
31 | 39 | | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
32 | 59 | | |
33 | 60 | | |
34 | 61 | | |
| |||
138 | 165 | | |
139 | 166 | | |
140 | 167 | | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
141 | 175 | | |
142 | 176 | | |
143 | 177 | | |
| |||
0 commit comments