MCPcopy Create free account
hub / github.com/apache/maka / killWindowsTree

Function killWindowsTree

packages/runtime/src/process-tree-terminator.ts:190–216  ·  view source on GitHub ↗
(pid: number)

Source from the content-addressed store, hash-verified

188
189/** Force-kill a Windows process tree and wait for taskkill's exit status. */
190export function killWindowsTree(pid: number): Promise<boolean> {
191 return new Promise((resolve) => {
192 let settled = false;
193 let timeout: NodeJS.Timeout | undefined;
194 const finish = (succeeded: boolean) => {
195 if (settled) return;
196 settled = true;
197 if (timeout) clearTimeout(timeout);
198 resolve(succeeded);
199 };
200 try {
201 const killer = spawn('taskkill', ['/pid', String(pid), '/t', '/f'], { stdio: 'ignore' });
202 killer.once('error', () => finish(false));
203 killer.once('close', (code) => finish(code === 0));
204 timeout = setTimeout(() => {
205 try {
206 killer.kill();
207 } catch {
208 /* taskkill already exited */
209 }
210 finish(false);
211 }, WINDOWS_TASKKILL_TIMEOUT_MS);
212 } catch {
213 finish(false);
214 }
215 });
216}

Callers 2

terminateProcessTreeFunction · 0.85
shell-exec.test.tsFile · 0.85

Calls 4

onceMethod · 0.80
finishFunction · 0.70
setTimeoutFunction · 0.70
killMethod · 0.65

Tested by

no test coverage detected