MCPcopy
hub / github.com/openclaw/clawsweeper / terminateCodexProcessTree

Function terminateCodexProcessTree

src/codex-spawn.ts:50–73  ·  view source on GitHub ↗
(
  child: ChildProcess,
  signal: NodeJS.Signals = "SIGTERM",
  forceAfterMs = 1_000,
)

Source from the content-addressed store, hash-verified

48}
49
50export 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
75export function waitForCodexProcessExit(child: ChildProcess, timeoutMs = 2_000): Promise<void> {
76 if (child.exitCode !== null || child.signalCode !== null) return Promise.resolve();

Callers 4

finishFunction · 0.85
spawnCodexWithHeartbeatFunction · 0.85

Calls 2

windowsSystemExecutableFunction · 0.85
signalPosixProcessGroupFunction · 0.85

Tested by

no test coverage detected