MCPcopy
hub / github.com/microsoft/vscode-js-debug / getProcessTree

Function getProcessTree

src/targets/node/nodeAttacherCluster.ts:76–109  ·  view source on GitHub ↗

* Returns a process tree rooting at the give process ID.

(
  rootPid: number,
  logger: ILogger,
)

Source from the content-addressed store, hash-verified

74 * Returns a process tree rooting at the give process ID.
75 */
76async function getProcessTree(
77 rootPid: number,
78 logger: ILogger,
79): Promise<IProcessTreeNode | undefined> {
80 const map = new Map<number, IProcessTreeNode>();
81
82 map.set(0, { children: [], pid: 0, ppid: 0, command: '', args: '' });
83
84 try {
85 await processTree.lookup(({ pid, ppid, command, args }) => {
86 if (pid !== ppid) {
87 map.set(pid, { pid, ppid, command, args, children: [] });
88 }
89 return map;
90 }, null);
91 } catch (err) {
92 logger.warn(LogTag.Internal, 'Error getting child process tree', err);
93 return undefined;
94 }
95
96 const values = map.values();
97 for (const p of values) {
98 const parent = map.get(p.ppid);
99 if (parent && parent !== p) {
100 parent.children.push(p);
101 }
102 }
103
104 if (!isNaN(rootPid) && rootPid > 0) {
105 return map.get(rootPid);
106 }
107
108 return map.get(0);
109}

Callers 1

watchAllChildrenFunction · 0.85

Calls 6

valuesMethod · 0.80
setMethod · 0.65
lookupMethod · 0.65
warnMethod · 0.65
getMethod · 0.65
pushMethod · 0.65

Tested by

no test coverage detected