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:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user