processLoad() fix pid (linux)
This commit is contained in:
parent
131f02dd5b
commit
cc186f6781
@ -1122,7 +1122,7 @@ function processLoad(proc, callback) {
|
||||
}
|
||||
|
||||
if (_darwin || _linux || _freebsd || _openbsd || _netbsd) {
|
||||
const params = ['-axo', 'pid,pcpu,pmem,comm'];
|
||||
const params = ['-axo', 'pid,ppid,pcpu,pmem,comm'];
|
||||
util.execSafe('ps', params).then((stdout) => {
|
||||
if (stdout) {
|
||||
let procStats = [];
|
||||
@ -1138,12 +1138,13 @@ function processLoad(proc, callback) {
|
||||
|
||||
lines.forEach(function (line) {
|
||||
let data = line.trim().replace(/ +/g, ' ').split(' ');
|
||||
if (data.length > 3) {
|
||||
if (data.length > 4) {
|
||||
procStats.push({
|
||||
name: data[3].substring(data[3].lastIndexOf('/') + 1),
|
||||
name: data[4].substring(data[4].lastIndexOf('/') + 1),
|
||||
pid: parseInt(data[0]) || 0,
|
||||
cpu: parseFloat(data[1].replace(',', '.')),
|
||||
mem: parseFloat(data[2].replace(',', '.'))
|
||||
ppid: parseInt(data[0]) || 0,
|
||||
cpu: parseFloat(data[2].replace(',', '.')),
|
||||
mem: parseFloat(data[3].replace(',', '.'))
|
||||
});
|
||||
}
|
||||
});
|
||||
@ -1168,12 +1169,15 @@ function processLoad(proc, callback) {
|
||||
if (listPos < 0) {
|
||||
result.push({
|
||||
proc: name,
|
||||
pid: item.pid,
|
||||
pid: item.ppid < 10 ? item.pid : null,
|
||||
pids: [item.pid],
|
||||
cpu: item.cpu,
|
||||
mem: item.mem
|
||||
});
|
||||
} else {
|
||||
if (item.ppid < 10) {
|
||||
result[listPos].pid = item.pid;
|
||||
}
|
||||
result[listPos].pids.push(item.pid);
|
||||
result[listPos].cpu += item.cpu;
|
||||
result[listPos].mem += item.mem;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user