fetch from upstream arrpc

This commit is contained in:
smartfrigde 2023-08-28 23:16:17 +02:00
parent ebe2e6d693
commit da141beb3e

View file

@ -1,31 +1,16 @@
const {exec} = require("child_process"); const {readlink, readdir} = require("fs/promises");
const {readlink} = require("fs/promises");
const getProcesses = () => const getProcesses = async () => {
new Promise((res) => const pids = (await readdir("/proc")).filter((f) => !isNaN(+f));
exec(`ps a -o "%p;%c;%a"`, async (e, out) => { return (
res( await Promise.all(
( pids.map((pid) =>
await Promise.all( readlink(`/proc/${pid}/exe`).then(
out (path) => [+pid, path],
.toString() () => {}
.split("\n") )
.slice(1, -1) )
.map(async (x) => { )
const split = x.trim().split(";"); ).filter((x) => x);
// if (split.length === 1) return; };
const pid = parseInt(split[0].trim());
const cmd = split[1].trim();
const argv = split.slice(2).join(";").trim();
const path = await readlink(`/proc/${pid}/exe`).catch((e) => {}); // read path from /proc/{pid}/exe symlink
return [pid, path];
})
)
).filter((x) => x && x[1])
);
})
);
module.exports = {getProcesses}; module.exports = {getProcesses};