1
0
mirror of https://github.com/Ylianst/MeshAgent synced 2025-12-15 07:43:50 +00:00

Added 'getProcessEx()' to process-manager

This commit is contained in:
Bryan Roe
2019-11-14 16:38:54 -08:00
parent 895ff6be15
commit dfcfc91df3
2 changed files with 23 additions and 1 deletions

File diff suppressed because one or more lines are too long

View File

@@ -216,6 +216,28 @@ function processManager() {
return (parseInt(child.stdout.str.trim()));
};
}
if(process.platform != 'win32')
{
this.getProcessEx = function getProcessEx(cmd)
{
var child = require('child_process').execFile('/bin/sh', ['sh']);
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
child.stderr.str = ''; child.stderr.on('data', function (c) { this.str += c.toString(); });
child.stdin.write('ps -ax -o pid -o command | grep ' + cmd + " | tr '\\n' '\\t' | awk -F" + '"\\t" \'{ for(i=1;i<NF;++i) { split($i,r," "); if(r[2]!="grep") { print r[1]; break; } } }\'');
child.stdin.write('\nexit\n');
child.waitExit();
if (child.stdout.str.trim() == '')
{
throw (cmd + ' not found');
}
else
{
return (parseInt(child.stdout.str.trim()));
}
}
}
}
module.exports = new processManager();