* Get the PID of the process listening on a port (macOS/Linux only). * Returns null on Windows or if detection fails.
(port: number)
| 189 | * Returns null on Windows or if detection fails. |
| 190 | */ |
| 191 | async function getProcessOnPort(port: number): Promise<string | null> { |
| 192 | if (process.platform === "win32") return null; |
| 193 | try { |
| 194 | const { stdout } = await execFileAsync("lsof", [`-ti:${port}`, "-sTCP:LISTEN"], { |
| 195 | timeout: 2000, |
| 196 | }); |
| 197 | const pid = stdout.trim().split("\n")[0]?.trim(); |
| 198 | return pid || null; |
| 199 | } catch { |
| 200 | return null; |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | // ── Server discovery ─────────────────────────────────────────────────────── |
| 205 |
no outgoing calls
no test coverage detected