(processName: string)
| 86 | } |
| 87 | |
| 88 | function killOrphansByName(processName: string): number { |
| 89 | const uid = getUid(); |
| 90 | const userFlag = uid !== null ? `-u ${uid} ` : ""; |
| 91 | let pids: number[]; |
| 92 | try { |
| 93 | const raw = execSync(`pgrep ${userFlag}-f ${processName}`, { |
| 94 | encoding: "utf-8", |
| 95 | timeout: 3000, |
| 96 | }).trim(); |
| 97 | if (!raw) return 0; |
| 98 | pids = raw |
| 99 | .split("\n") |
| 100 | .map((s) => parseInt(s, 10)) |
| 101 | .filter((n) => !isNaN(n) && n > 0); |
| 102 | } catch { |
| 103 | return 0; |
| 104 | } |
| 105 | |
| 106 | let killed = 0; |
| 107 | for (const pid of pids) { |
| 108 | if (!isOrphan(pid)) continue; |
| 109 | killProcessTree(pid); |
| 110 | killed++; |
| 111 | } |
| 112 | return killed; |
| 113 | } |
| 114 | |
| 115 | let _cachedUid: string | null | undefined; |
| 116 |
no test coverage detected