(parentPid: number, pids: Record<string, Array<number>> = {})
| 703 | } |
| 704 | |
| 705 | async function ps(parentPid: number, pids: Record<string, Array<number>> = {}) { |
| 706 | const cmd: string[] = |
| 707 | process.platform === 'darwin' |
| 708 | ? ['pgrep', '-P', parentPid.toString()] |
| 709 | : ['ps', '-o', 'pid', '--no-headers', '--ppid', parentPid.toString()]; |
| 710 | |
| 711 | try { |
| 712 | const buf = execFileSync(cmd[0], cmd.slice(1), { |
| 713 | encoding: 'utf-8', |
| 714 | }); |
| 715 | const possiblePids = buf.match(/\d+/g) || []; |
| 716 | for (const rawPid of possiblePids) { |
| 717 | const pid = parseInt(rawPid); |
| 718 | const recurse = Object.prototype.hasOwnProperty.call(pids, pid); |
| 719 | pids[parentPid].push(pid); |
| 720 | pids[pid] = []; |
| 721 | if (recurse) { |
| 722 | await ps(pid, pids); |
| 723 | } |
| 724 | } |
| 725 | } catch (err) { |
| 726 | const error = err as Error; |
| 727 | console.log(`Failed to get processes: ${error.toString()}`); |
| 728 | } |
| 729 | return pids; |
| 730 | } |
| 731 | |
| 732 | async function nukePID( |
| 733 | pid: number, |
no test coverage detected