Skip to content

Commit 642312e

Browse files
processLoad() linux fix * (linux)
1 parent 6ffb79a commit 642312e

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

lib/processes.js

+15-11
Original file line numberDiff line numberDiff line change
@@ -1005,7 +1005,7 @@ function processLoad(proc, callback) {
10051005
let processes = processesString.split('|');
10061006
let result = [];
10071007

1008-
const procSanitized = util.isPrototypePolluted() ? '' : util.sanitizeShellString(proc);
1008+
const procSanitized = util.isPrototypePolluted() ? '' : (util.sanitizeShellString(proc) || '*');
10091009

10101010
// from here new
10111011
// let result = {
@@ -1149,12 +1149,14 @@ function processLoad(proc, callback) {
11491149
});
11501150
return found;
11511151
});
1152-
1152+
lines.shift();
11531153
lines.forEach(function (line) {
11541154
let data = line.trim().replace(/ +/g, ' ').split(' ');
11551155
if (data.length > 4) {
1156+
const linuxName = data[4].indexOf('/') >= 0 ? data[4].substring(0, data[4].indexOf('/') - 1) : data[4];
1157+
const name = _linux ? (linuxName) : data[4].substring(data[4].lastIndexOf('/') + 1);
11561158
procStats.push({
1157-
name: data[4].substring(data[4].lastIndexOf('/') + 1),
1159+
name,
11581160
pid: parseInt(data[0]) || 0,
11591161
ppid: parseInt(data[1]) || 0,
11601162
cpu: parseFloat(data[2].replace(',', '.')),
@@ -1166,7 +1168,7 @@ function processLoad(proc, callback) {
11661168
procStats.forEach(function (item) {
11671169
let listPos = -1;
11681170
let inList = false;
1169-
let name = '';
1171+
let name = item.name;
11701172
for (let j = 0; j < result.length; j++) {
11711173
if (item.name.toLowerCase().indexOf(result[j].proc.toLowerCase()) >= 0) {
11721174
listPos = j;
@@ -1181,13 +1183,15 @@ function processLoad(proc, callback) {
11811183
});
11821184
if ((processesString === '*') || inList) {
11831185
if (listPos < 0) {
1184-
result.push({
1185-
proc: name,
1186-
pid: item.pid,
1187-
pids: [item.pid],
1188-
cpu: item.cpu,
1189-
mem: item.mem
1190-
});
1186+
if (name) {
1187+
result.push({
1188+
proc: name,
1189+
pid: item.pid,
1190+
pids: [item.pid],
1191+
cpu: item.cpu,
1192+
mem: item.mem
1193+
});
1194+
}
11911195
} else {
11921196
if (item.ppid < 10) {
11931197
result[listPos].pid = item.pid;

0 commit comments

Comments
 (0)