* Validate that a running process is actually a Claude process * This helps mitigate PID reuse issues
(pid: number, expectedExecPath: string)
| 99 | * This helps mitigate PID reuse issues |
| 100 | */ |
| 101 | function isClaudeProcess(pid: number, expectedExecPath: string): boolean { |
| 102 | if (!isProcessRunning(pid)) { |
| 103 | return false |
| 104 | } |
| 105 | |
| 106 | // If the PID matches our current process, we know it's valid |
| 107 | // This handles test environments where the command might not contain 'claude' |
| 108 | if (pid === process.pid) { |
| 109 | return true |
| 110 | } |
| 111 | |
| 112 | try { |
| 113 | const command = getProcessCommand(pid) |
| 114 | if (!command) { |
| 115 | // If we can't get the command, trust the PID check |
| 116 | // This is conservative - we'd rather not delete a running version |
| 117 | return true |
| 118 | } |
| 119 | |
| 120 | // Check if the command contains 'claude' or the expected exec path |
| 121 | const normalizedCommand = command.toLowerCase() |
| 122 | const normalizedExecPath = expectedExecPath.toLowerCase() |
| 123 | |
| 124 | return ( |
| 125 | normalizedCommand.includes('claude') || |
| 126 | normalizedCommand.includes(normalizedExecPath) |
| 127 | ) |
| 128 | } catch { |
| 129 | // If command check fails, trust the PID check |
| 130 | return true |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | /** |
| 135 | * Read and parse a lock file's content |
no test coverage detected