mirror of
https://github.com/Ylianst/MeshAgent
synced 2025-12-16 16:23:25 +00:00
Added 'getProcessEx()' to process-manager
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -216,6 +216,28 @@ function processManager() {
|
|||||||
return (parseInt(child.stdout.str.trim()));
|
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();
|
module.exports = new processManager();
|
||||||
|
|||||||
Reference in New Issue
Block a user