A pid that's guaranteed dead: spawn a trivial process, let it exit, reap it.
()
| 14 | |
| 15 | /** A pid that's guaranteed dead: spawn a trivial process, let it exit, reap it. */ |
| 16 | async function deadPid(): Promise<number> { |
| 17 | const child = spawn(process.execPath, ['-e', 'process.exit(0)']); |
| 18 | const pid = child.pid!; |
| 19 | await new Promise<void>((r) => child.on('exit', () => r())); |
| 20 | await new Promise((r) => setTimeout(r, 50)); // let the OS reap it |
| 21 | return pid; |
| 22 | } |
| 23 | |
| 24 | function rec(root: string, pid: number, startedAt = Date.now()): DaemonRecord { |
| 25 | return { root, pid, version: '1.0.0', socketPath: `${root}/.codegraph/daemon.sock`, startedAt }; |
no test coverage detected