processLoad() linux fix * (linux)

This commit is contained in:
Sebastian Hildebrandt 2024-08-21 19:30:33 +02:00
parent 6ffb79aca3
commit 642312e166

View File

@ -1005,7 +1005,7 @@ function processLoad(proc, callback) {
let processes = processesString.split('|');
let result = [];
const procSanitized = util.isPrototypePolluted() ? '' : util.sanitizeShellString(proc);
const procSanitized = util.isPrototypePolluted() ? '' : (util.sanitizeShellString(proc) || '*');
// from here new
// let result = {
@ -1149,12 +1149,14 @@ function processLoad(proc, callback) {
});
return found;
});
lines.shift();
lines.forEach(function (line) {
let data = line.trim().replace(/ +/g, ' ').split(' ');
if (data.length > 4) {
const linuxName = data[4].indexOf('/') >= 0 ? data[4].substring(0, data[4].indexOf('/') - 1) : data[4];
const name = _linux ? (linuxName) : data[4].substring(data[4].lastIndexOf('/') + 1);
procStats.push({
name: data[4].substring(data[4].lastIndexOf('/') + 1),
name,
pid: parseInt(data[0]) || 0,
ppid: parseInt(data[1]) || 0,
cpu: parseFloat(data[2].replace(',', '.')),
@ -1166,7 +1168,7 @@ function processLoad(proc, callback) {
procStats.forEach(function (item) {
let listPos = -1;
let inList = false;
let name = '';
let name = item.name;
for (let j = 0; j < result.length; j++) {
if (item.name.toLowerCase().indexOf(result[j].proc.toLowerCase()) >= 0) {
listPos = j;
@ -1181,6 +1183,7 @@ function processLoad(proc, callback) {
});
if ((processesString === '*') || inList) {
if (listPos < 0) {
if (name) {
result.push({
proc: name,
pid: item.pid,
@ -1188,6 +1191,7 @@ function processLoad(proc, callback) {
cpu: item.cpu,
mem: item.mem
});
}
} else {
if (item.ppid < 10) {
result[listPos].pid = item.pid;