( child: ChildProcess, signal: NodeJS.Signals = "SIGTERM", forceAfterMs = 1_000, )
| 48 | } |
| 49 | |
| 50 | export function terminateCodexProcessTree( |
| 51 | child: ChildProcess, |
| 52 | signal: NodeJS.Signals = "SIGTERM", |
| 53 | forceAfterMs = 1_000, |
| 54 | ): NodeJS.Timeout | undefined { |
| 55 | if (process.platform === "win32") { |
| 56 | if (child.pid) { |
| 57 | spawnSync( |
| 58 | windowsSystemExecutable("taskkill.exe", process.env), |
| 59 | ["/pid", String(child.pid), "/t", "/f"], |
| 60 | { |
| 61 | stdio: "ignore", |
| 62 | windowsHide: true, |
| 63 | }, |
| 64 | ); |
| 65 | } |
| 66 | return undefined; |
| 67 | } |
| 68 | |
| 69 | signalPosixProcessGroup(child, signal); |
| 70 | const timer = setTimeout(() => signalPosixProcessGroup(child, "SIGKILL"), forceAfterMs); |
| 71 | timer.unref(); |
| 72 | return timer; |
| 73 | } |
| 74 | |
| 75 | export function waitForCodexProcessExit(child: ChildProcess, timeoutMs = 2_000): Promise<void> { |
| 76 | if (child.exitCode !== null || child.signalCode !== null) return Promise.resolve(); |
no test coverage detected