NUEVA BUSQUEDA DE DATOS SRI
This commit is contained in:
13
node_modules/pstree.remy/lib/index.js
generated
vendored
13
node_modules/pstree.remy/lib/index.js
generated
vendored
@@ -4,7 +4,7 @@ const utils = require('./utils');
|
||||
var hasPS = true;
|
||||
|
||||
// discover if the OS has `ps`, and therefore can use psTree
|
||||
exec('ps', error => {
|
||||
exec('ps', (error) => {
|
||||
module.exports.hasPS = hasPS = !error;
|
||||
});
|
||||
|
||||
@@ -20,9 +20,14 @@ module.exports = function main(pid, callback) {
|
||||
utils
|
||||
.getStat()
|
||||
.then(utils.tree)
|
||||
.then(tree => utils.pidsForTree(tree, pid))
|
||||
.then(res => callback(null, res.map(p => p.PID)))
|
||||
.catch(error => callback(error));
|
||||
.then((tree) => utils.pidsForTree(tree, pid))
|
||||
.then((res) =>
|
||||
callback(
|
||||
null,
|
||||
res.map((p) => p.PID)
|
||||
)
|
||||
)
|
||||
.catch((error) => callback(error));
|
||||
};
|
||||
|
||||
if (!module.parent) {
|
||||
|
||||
19
node_modules/pstree.remy/lib/tree.js
generated
vendored
19
node_modules/pstree.remy/lib/tree.js
generated
vendored
@@ -1,12 +1,12 @@
|
||||
const spawn = require('child_process').spawn;
|
||||
|
||||
module.exports = function(rootPid, callback) {
|
||||
const tree = {};
|
||||
module.exports = function (rootPid, callback) {
|
||||
const pidsOfInterest = new Set([parseInt(rootPid, 10)]);
|
||||
var output = '';
|
||||
|
||||
// *nix
|
||||
const ps = spawn('ps', ['-A', '-o', 'ppid,pid']);
|
||||
ps.stdout.on('data', data => {
|
||||
ps.stdout.on('data', (data) => {
|
||||
output += data.toString('ascii');
|
||||
});
|
||||
|
||||
@@ -15,12 +15,15 @@ module.exports = function(rootPid, callback) {
|
||||
const res = output
|
||||
.split('\n')
|
||||
.slice(1)
|
||||
.map(_ => _.trim())
|
||||
.map((_) => _.trim())
|
||||
.reduce((acc, line) => {
|
||||
if (line.indexOf(rootPid + ' ') === 0) {
|
||||
const pid = line.split(/\s+/).pop();
|
||||
acc.push(parseInt(pid, 10));
|
||||
rootPid = pid;
|
||||
const pids = line.split(/\s+/);
|
||||
const ppid = parseInt(pids[0], 10);
|
||||
|
||||
if (pidsOfInterest.has(ppid)) {
|
||||
const pid = parseInt(pids[1], 10);
|
||||
acc.push(pid);
|
||||
pidsOfInterest.add(pid);
|
||||
}
|
||||
|
||||
return acc;
|
||||
|
||||
21
node_modules/pstree.remy/lib/utils.js
generated
vendored
21
node_modules/pstree.remy/lib/utils.js
generated
vendored
@@ -3,15 +3,15 @@ const spawn = require('child_process').spawn;
|
||||
module.exports = { tree, pidsForTree, getStat };
|
||||
|
||||
function getStat() {
|
||||
return new Promise(resolve => {
|
||||
return new Promise((resolve) => {
|
||||
const command = `ls /proc | grep -E '^[0-9]+$' | xargs -I{} cat /proc/{}/stat`;
|
||||
const child = spawn('sh', ['-c', command], {
|
||||
const spawned = spawn('sh', ['-c', command], {
|
||||
stdio: ['pipe', 'pipe', 'pipe'],
|
||||
});
|
||||
|
||||
var res = '';
|
||||
child.stdout.on('data', data => (res += data));
|
||||
child.on('close', () => resolve(res));
|
||||
spawned.stdout.on('data', (data) => (res += data));
|
||||
spawned.on('close', () => resolve(res));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -30,10 +30,7 @@ function template(s) {
|
||||
}
|
||||
|
||||
function tree(stats) {
|
||||
const processes = stats
|
||||
.split('\n')
|
||||
.map(template)
|
||||
.filter(Boolean);
|
||||
const processes = stats.split('\n').map(template).filter(Boolean);
|
||||
|
||||
return processes;
|
||||
}
|
||||
@@ -43,14 +40,14 @@ function pidsForTree(tree, pid) {
|
||||
pid = pid.toString();
|
||||
}
|
||||
const parents = [pid];
|
||||
const children = [];
|
||||
const pids = [];
|
||||
|
||||
tree.forEach(proc => {
|
||||
tree.forEach((proc) => {
|
||||
if (parents.indexOf(proc.PPID) !== -1) {
|
||||
parents.push(proc.PID);
|
||||
children.push(proc);
|
||||
pids.push(proc);
|
||||
}
|
||||
});
|
||||
|
||||
return children;
|
||||
return pids;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user