| 66 | } |
| 67 | |
| 68 | function getDescendants(pid: number): number[] { |
| 69 | let children: number[]; |
| 70 | try { |
| 71 | const raw = execSync(`pgrep -P ${pid}`, { encoding: "utf-8", timeout: 2000 }).trim(); |
| 72 | if (!raw) return []; |
| 73 | children = raw |
| 74 | .split("\n") |
| 75 | .map((s) => parseInt(s, 10)) |
| 76 | .filter((n) => !isNaN(n) && n > 0); |
| 77 | } catch { |
| 78 | return []; |
| 79 | } |
| 80 | const all: number[] = []; |
| 81 | for (const child of children) { |
| 82 | all.push(child); |
| 83 | all.push(...getDescendants(child)); |
| 84 | } |
| 85 | return all; |
| 86 | } |
| 87 | |
| 88 | function killOrphansByName(processName: string): number { |
| 89 | const uid = getUid(); |