diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e88b7b..c40cf61 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ For major (breaking) changes - version 3 and 2 see end of page. | Version | Date | Comment | | -------------- | -------------- | -------- | +| 4.14.0 | 2019-07-03 | `processes()` added process path and params | | 4.13.2 | 2019-07-02 | `versions()` fix getting all versions | | 4.13.1 | 2019-07-01 | `versions()` gcc fix macos | | 4.13.0 | 2019-07-01 | `networkConnections()` added PID and process | diff --git a/README.md b/README.md index 68ab79b..2a08fbc 100644 --- a/README.md +++ b/README.md @@ -84,13 +84,13 @@ si.cpu() (last 7 major and minor version releases) +- Version 4.14.0: `processes()` added process path and params - Version 4.13.0: `networkConnections()` added PID, process - Version 4.12.0: `networkInterfaces()` added property virtual - Version 4.11.0: `wifiNetworks()` added available wifi networks - Version 4.10.0: `graphics()` added windows multiple display support, added display size, connection, ... - Version 4.9.0: `graphics()` added vendor, refresh rate, current resolution - Version 4.8.0: added `vboxInfo()` detailed virtual box info -- Version 4.7.0: partial NetBSD support - ... You can find all changes here: [detailed changelog][changelog-url] @@ -333,7 +333,8 @@ I also created a nice little command line tool called [mmon][mmon-github-url] ( | | ...[0].tty | X | X | X | | X | tty from which process was started | | | ...[0].user | X | X | X | | X | user who started process | | | ...[0].command | X | X | X | X | X | process starting command | -| si.processLoad('apache2',cb) | {...} | X | X | X | X | | detailed information about given process | +| | ...[0].params | X | X | X | | X | process params | +| | ...[0].path | X | X | X | X | X | process path | | | proc | X | X | X | X | | process name | | | pid | X | X | X | X | | PID | | | pids | X | X | X | X | | additional pids | diff --git a/docs/history.html b/docs/history.html index 30ba79a..8e89aee 100644 --- a/docs/history.html +++ b/docs/history.html @@ -83,6 +83,11 @@ + + 4.14.0 + 2019-07-03 + processes() added process params and path + 4.13.2 2019-07-02 diff --git a/docs/index.html b/docs/index.html index 512a2ac..2dce217 100644 --- a/docs/index.html +++ b/docs/index.html @@ -168,7 +168,7 @@
systeminformation
-
Current Version: 4.13.2
+
Current Version: 4.14.0
@@ -191,7 +191,7 @@
-
9,183
+
9,213
Lines of code
diff --git a/docs/processes.html b/docs/processes.html index 9014c12..3abfcf4 100644 --- a/docs/processes.html +++ b/docs/processes.html @@ -405,6 +405,26 @@ X process starting command + + + ...[0].params + X + X + X + + X + process params + + + + ...[0].path + X + X + X + X + X + process path + si.processLoad('apache2',cb) {...} diff --git a/lib/index.d.ts b/lib/index.d.ts index e874fe4..58924f3 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -420,6 +420,8 @@ export namespace Systeminformation { tty: string; user: string; command: string; + params: string; + path: string; } interface ProcessesProcessLoadData { diff --git a/lib/processes.js b/lib/processes.js index d3a177b..b119a1d 100644 --- a/lib/processes.js +++ b/lib/processes.js @@ -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: '' }); } }