Skip to content

Commit

Permalink
processLoad() linux fix * (linux)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebhildebrandt committed Aug 21, 2024
1 parent 6ffb79a commit 642312e
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions lib/processes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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(',', '.')),
Expand All @@ -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;
Expand All @@ -1181,13 +1183,15 @@ function processLoad(proc, callback) {
});
if ((processesString === '*') || inList) {
if (listPos < 0) {
result.push({
proc: name,
pid: item.pid,
pids: [item.pid],
cpu: item.cpu,
mem: item.mem
});
if (name) {
result.push({
proc: name,
pid: item.pid,
pids: [item.pid],
cpu: item.cpu,
mem: item.mem
});
}
} else {
if (item.ppid < 10) {
result[listPos].pid = item.pid;
Expand Down

0 comments on commit 642312e

Please sign in to comment.