processes() added process params and path
This commit is contained in:
Vendored
+2
@@ -420,6 +420,8 @@ export namespace Systeminformation {
|
||||
tty: string;
|
||||
user: string;
|
||||
command: string;
|
||||
params: string;
|
||||
path: string;
|
||||
}
|
||||
|
||||
interface ProcessesProcessLoadData {
|
||||
|
||||
+44
-14
@@ -439,23 +439,23 @@ function processes(callback) {
|
||||
}
|
||||
|
||||
checkColumn(0);
|
||||
let pid = parseInt(line.substring(parsedhead[0].from + offset, parsedhead[0].to + offset2));
|
||||
const pid = parseInt(line.substring(parsedhead[0].from + offset, parsedhead[0].to + offset2));
|
||||
checkColumn(1);
|
||||
let ppid = parseInt(line.substring(parsedhead[1].from + offset, parsedhead[1].to + offset2));
|
||||
const ppid = parseInt(line.substring(parsedhead[1].from + offset, parsedhead[1].to + offset2));
|
||||
checkColumn(2);
|
||||
let pcpu = parseFloat(line.substring(parsedhead[2].from + offset, parsedhead[2].to + offset2).replace(/,/g, '.'));
|
||||
const pcpu = parseFloat(line.substring(parsedhead[2].from + offset, parsedhead[2].to + offset2).replace(/,/g, '.'));
|
||||
checkColumn(3);
|
||||
let pmem = parseFloat(line.substring(parsedhead[3].from + offset, parsedhead[3].to + offset2).replace(/,/g, '.'));
|
||||
const pmem = parseFloat(line.substring(parsedhead[3].from + offset, parsedhead[3].to + offset2).replace(/,/g, '.'));
|
||||
checkColumn(4);
|
||||
let priority = parseInt(line.substring(parsedhead[4].from + offset, parsedhead[4].to + offset2));
|
||||
const priority = parseInt(line.substring(parsedhead[4].from + offset, parsedhead[4].to + offset2));
|
||||
checkColumn(5);
|
||||
let vsz = parseInt(line.substring(parsedhead[5].from + offset, parsedhead[5].to + offset2));
|
||||
const vsz = parseInt(line.substring(parsedhead[5].from + offset, parsedhead[5].to + offset2));
|
||||
checkColumn(6);
|
||||
let rss = parseInt(line.substring(parsedhead[6].from + offset, parsedhead[6].to + offset2));
|
||||
const rss = parseInt(line.substring(parsedhead[6].from + offset, parsedhead[6].to + offset2));
|
||||
checkColumn(7);
|
||||
let nice = parseInt(line.substring(parsedhead[7].from + offset, parsedhead[7].to + offset2)) || 0;
|
||||
const nice = parseInt(line.substring(parsedhead[7].from + offset, parsedhead[7].to + offset2)) || 0;
|
||||
checkColumn(8);
|
||||
let started = parseTimeUnix(line.substring(parsedhead[8].from + offset, parsedhead[8].to + offset2).trim());
|
||||
const started = parseTimeUnix(line.substring(parsedhead[8].from + offset, parsedhead[8].to + offset2).trim());
|
||||
checkColumn(9);
|
||||
let state = line.substring(parsedhead[9].from + offset, parsedhead[9].to + offset2).trim();
|
||||
state = (state[0] === 'R' ? 'running' : (state[0] === 'S' ? 'sleeping' : (state[0] === 'T' ? 'stopped' : (state[0] === 'W' ? 'paging' : (state[0] === 'X' ? 'dead' : (state[0] === 'Z' ? 'zombie' : ((state[0] === 'D' || state[0] === 'U') ? 'blocked' : 'unknown')))))));
|
||||
@@ -463,9 +463,34 @@ function processes(callback) {
|
||||
let tty = line.substring(parsedhead[10].from + offset, parsedhead[10].to + offset2).trim();
|
||||
if (tty === '?' || tty === '??') tty = '';
|
||||
checkColumn(11);
|
||||
let user = line.substring(parsedhead[11].from + offset, parsedhead[11].to + offset2).trim();
|
||||
const user = line.substring(parsedhead[11].from + offset, parsedhead[11].to + offset2).trim();
|
||||
checkColumn(12);
|
||||
let command = line.substring(parsedhead[12].from + offset, parsedhead[12].to + offset2).trim().replace(/\[/g, '').replace(/]/g, '');
|
||||
const fullcommand = line.substring(parsedhead[12].from + offset, parsedhead[12].to + offset2).trim().replace(/\[/g, '').replace(/]/g, '');
|
||||
let path = '';
|
||||
let command = '';
|
||||
let params = '';
|
||||
// try to figure out where parameter starts
|
||||
let firstParamPos = fullcommand.indexOf(' -')
|
||||
let firstParamPathPos = fullcommand.indexOf(' /')
|
||||
firstParamPos = (firstParamPos >= 0 ? firstParamPos : 10000);
|
||||
firstParamPathPos = (firstParamPathPos >= 0 ? firstParamPathPos : 10000);
|
||||
const firstPos = Math.min(firstParamPos, firstParamPathPos);
|
||||
let tmpCommand = fullcommand.substr(0, firstPos);
|
||||
const tmpParams = fullcommand.substr(firstPos);
|
||||
const lastSlashPos = tmpCommand.lastIndexOf('/');
|
||||
if (lastSlashPos >= 0) {
|
||||
path = tmpCommand.substr(0, lastSlashPos);
|
||||
tmpCommand = tmpCommand.substr(lastSlashPos + 1);
|
||||
}
|
||||
|
||||
if (firstPos === 10000) {
|
||||
const parts = tmpCommand.split(' ');
|
||||
command = parts.shift();
|
||||
params = (parts.join(' ') + ' ' + tmpParams).trim();
|
||||
} else {
|
||||
command = tmpCommand.trim();
|
||||
params = tmpParams.trim();
|
||||
}
|
||||
|
||||
return ({
|
||||
pid: pid,
|
||||
@@ -483,7 +508,9 @@ function processes(callback) {
|
||||
state: state,
|
||||
tty: tty,
|
||||
user: user,
|
||||
command: command
|
||||
command: command,
|
||||
params: params,
|
||||
path: path
|
||||
});
|
||||
}
|
||||
|
||||
@@ -564,7 +591,7 @@ function processes(callback) {
|
||||
if (_linux || _freebsd || _openbsd || _netbsd || _darwin || _sunos) {
|
||||
if (_linux) cmd = 'export LC_ALL=C; ps -axo pid:11,ppid:11,pcpu:6,pmem:6,pri:5,vsz:11,rss:11,ni:5,lstart:30,state:5,tty:15,user:20,command; unset LC_ALL';
|
||||
if (_freebsd || _openbsd || _netbsd) cmd = 'export LC_ALL=C; ps -axo pid,ppid,pcpu,pmem,pri,vsz,rss,ni,lstart,state,tty,user,command; unset LC_ALL';
|
||||
if (_darwin) cmd = 'export LC_ALL=C; ps -acxo pid,ppid,pcpu,pmem,pri,vsz,rss,nice,lstart,state,tty,user,command -r; unset LC_ALL';
|
||||
if (_darwin) cmd = 'export LC_ALL=C; ps -axo pid,ppid,pcpu,pmem,pri,vsz,rss,nice,lstart,state,tty,user,command -r; unset LC_ALL';
|
||||
if (_sunos) cmd = 'ps -Ao pid,ppid,pcpu,pmem,pri,vsz,rss,nice,stime,s,tty,user,comm';
|
||||
exec(cmd, { maxBuffer: 1024 * 20000 }, function (error, stdout) {
|
||||
if (!error) {
|
||||
@@ -681,6 +708,7 @@ function processes(callback) {
|
||||
let statusValue = util.getValue(lines, 'ExecutionState', '=');
|
||||
let name = util.getValue(lines, 'Caption', '=', true);
|
||||
let commandLine = util.getValue(lines, 'CommandLine', '=', true);
|
||||
let commandPath = util.getValue(lines, 'ExecutablePath', '=', true);
|
||||
let utime = parseInt(util.getValue(lines, 'UserModeTime', '=', true), 10);
|
||||
let stime = parseInt(util.getValue(lines, 'KernelModeTime', '=', true), 10);
|
||||
let mem = parseInt(util.getValue(lines, 'WorkingSetSize', '=', true), 10);
|
||||
@@ -715,7 +743,9 @@ function processes(callback) {
|
||||
state: (!statusValue ? _winStatusValues[0] : _winStatusValues[statusValue]),
|
||||
tty: '',
|
||||
user: '',
|
||||
command: commandLine || name
|
||||
command: commandLine || name,
|
||||
path: commandPath,
|
||||
params: ''
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user