MCPcopy Create free account
hub / github.com/cloudflare/templates / killProcessTree

Function killProcessTree

playwright-tests/utils/template-server.ts:15–51  ·  view source on GitHub ↗
(pid: number)

Source from the content-addressed store, hash-verified

13// Helper function to kill the complete process tree without leaving dev servers
14// behind between Playwright runs.
15async function killProcessTree(pid: number): Promise<void> {
16 if (process.platform === "win32") {
17 await new Promise<void>((resolve) => {
18 const taskkill = spawn("taskkill", ["/pid", pid.toString(), "/T", "/F"], {
19 stdio: "ignore",
20 });
21 taskkill.once("close", () => resolve());
22 taskkill.once("error", () => resolve());
23 });
24 return;
25 }
26
27 const processGroupExists = () => {
28 try {
29 process.kill(-pid, 0);
30 return true;
31 } catch {
32 return false;
33 }
34 };
35
36 try {
37 process.kill(-pid, "SIGTERM");
38 } catch {
39 return;
40 }
41 for (let attempt = 0; attempt < 20 && processGroupExists(); attempt++) {
42 await new Promise((resolve) => setTimeout(resolve, 50));
43 }
44 if (processGroupExists()) {
45 try {
46 process.kill(-pid, "SIGKILL");
47 } catch {
48 // Process group exited between the liveness check and signal.
49 }
50 }
51}
52
53export interface Template {
54 name: string;

Callers 1

stopServerMethod · 0.85

Calls 3

processGroupExistsFunction · 0.85
toStringMethod · 0.65
killMethod · 0.65

Tested by

no test coverage detected