(processes: Process[])
| 56 | } |
| 57 | |
| 58 | export function buildProcessTrees(processes: Process[]) { |
| 59 | const index: Record<string, ProcessTree> = {}; |
| 60 | processes.forEach(process => index[process.pid] = { process, childProcesses: [] }); |
| 61 | processes.filter(p => p.ppid) |
| 62 | .forEach(p => index[p.ppid!]?.childProcesses.push(index[p.pid])); |
| 63 | return index; |
| 64 | } |
| 65 | |
| 66 | export function processTreeToString(tree: ProcessTree, singleIndent = ' ', currentIndent = ' '): string { |
| 67 | return `${currentIndent}${tree.process.pid}: ${tree.process.cmd} |