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;
|
||||
}
|
||||
|
||||
95
node_modules/pstree.remy/package.json
generated
vendored
95
node_modules/pstree.remy/package.json
generated
vendored
@@ -1,82 +1,33 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
"pstree.remy@^1.1.7",
|
||||
"/home/pablinux/Projects/Node/app_sigma/node_modules/nodemon"
|
||||
]
|
||||
"name": "pstree.remy",
|
||||
"version": "1.1.8",
|
||||
"main": "lib/index.js",
|
||||
"prettier": {
|
||||
"trailingComma": "es5",
|
||||
"semi": true,
|
||||
"singleQuote": true
|
||||
},
|
||||
"scripts": {
|
||||
"test": "tap tests/*.test.js",
|
||||
"_prepublish": "npm test"
|
||||
},
|
||||
"keywords": [
|
||||
"ps",
|
||||
"pstree",
|
||||
"ps tree"
|
||||
],
|
||||
"_from": "pstree.remy@>=1.1.7 <2.0.0",
|
||||
"_hasShrinkwrap": false,
|
||||
"_id": "pstree.remy@1.1.7",
|
||||
"_inCache": true,
|
||||
"_installable": true,
|
||||
"_location": "/pstree.remy",
|
||||
"_nodeVersion": "10.14.1",
|
||||
"_npmOperationalInternal": {
|
||||
"host": "s3://npm-registry-packages",
|
||||
"tmp": "tmp/pstree.remy_1.1.7_1559148737521_0.016928364077606783"
|
||||
"author": "Remy Sharp",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/remy/pstree.git"
|
||||
},
|
||||
"_npmUser": {
|
||||
"email": "remy@leftlogic.com",
|
||||
"name": "remy"
|
||||
},
|
||||
"_npmVersion": "6.4.1",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"name": "pstree.remy",
|
||||
"raw": "pstree.remy@^1.1.7",
|
||||
"rawSpec": "^1.1.7",
|
||||
"scope": null,
|
||||
"spec": ">=1.1.7 <2.0.0",
|
||||
"type": "range"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/nodemon"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/pstree.remy/-/pstree.remy-1.1.7.tgz",
|
||||
"_shasum": "c76963a28047ed61542dc361aa26ee55a7fa15f3",
|
||||
"_shrinkwrap": null,
|
||||
"_spec": "pstree.remy@^1.1.7",
|
||||
"_where": "/home/pablinux/Projects/Node/app_sigma/node_modules/nodemon",
|
||||
"author": {
|
||||
"name": "Remy Sharp"
|
||||
},
|
||||
"dependencies": {},
|
||||
"description": "Collects the full tree of processes from /proc",
|
||||
"devDependencies": {
|
||||
"tap": "^11.0.0"
|
||||
},
|
||||
"directories": {
|
||||
"test": "tests"
|
||||
},
|
||||
"dist": {
|
||||
"fileCount": 10,
|
||||
"integrity": "sha512-xsMgrUwRpuGskEzBFkH8NmTimbZ5PcPup0LA8JJkHIm2IMUbQcpo3yeLNWVrufEYjh8YwtSVh0xz6UeWc5Oh5A==",
|
||||
"npm-signature": "-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJc7rjCCRA9TVsSAnZWagAAtxIP/2e40kOGpmd44OswAcXF\nJ1cogI9DFlAmzMYJBHl4l54jKoN6WUqxfNKhF4qH9D3S1Izh4dTg8Z4xqC9I\nqeC4SgeoXPV65flq0+cbRMfXmI9QDlgy80HY0PBZqZYU3sM587nNxkNKv7T2\nWn8l5ApsFpBJa1hqnIU2HRTuRtUXRH1erVPtcvA0xBPFzr1CwMwmM56krqdX\n1ZjQpgj/jBdoBN5i0JaukVoh7t5RD/llBJn2bB0HEhB7oMKMUywoELS55ZMR\nWydtqUyldD+uHcvWgyEwLJIZxPQSQuw+gTxemoUs0USzb+Qz8E+detdcyJGe\n9UvLx79Kpcm+EHTb09v50RtW4szcnz83w+xzrh3+e82PP/IeOhfp8HjbgwId\nZCt6cm4MuL3acG1L9A2Dh9BQSGZHq9Hh9sUgmCwJRynOuDmazNieBzsgrpfV\nSRo8jitqfX8vzltmXFGGTwt7HYRICAfNssLklKiWp0U/dk2AIrketuAlj5Fa\n2Sf0DKi2LqANJ4mBd/8SVhyD/JxhSdnJ1YsPs5AXKBHw7N6HctTremaEvikI\nKwKNl/qBXuiAOrQyeh2LqA+nc9gSDFuu4G7e3bIMC7GFXaoyG6P47VYxMLI2\nv8/4qnw9td+puRRVxX3IvwPccg1PQY2I0fHsdnwfZ4vDyGc/wHiaXqjMpn1d\nIqQb\r\n=6nX7\r\n-----END PGP SIGNATURE-----\r\n",
|
||||
"shasum": "c76963a28047ed61542dc361aa26ee55a7fa15f3",
|
||||
"tarball": "https://registry.npmjs.org/pstree.remy/-/pstree.remy-1.1.7.tgz",
|
||||
"unpackedSize": 13779
|
||||
},
|
||||
"gitHead": "44da1174fc8a0c68d7bc30cacad9cec28c50f64e",
|
||||
"keywords": [
|
||||
"ps",
|
||||
"ps tree",
|
||||
"pstree"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "lib/index.js",
|
||||
"maintainers": [
|
||||
{
|
||||
"name": "remy",
|
||||
"email": "remy@leftlogic.com"
|
||||
}
|
||||
],
|
||||
"name": "pstree.remy",
|
||||
"optionalDependencies": {},
|
||||
"readme": "ERROR: No README data found!",
|
||||
"scripts": {
|
||||
"_prepublish": "npm test",
|
||||
"test": "tap tests/*.test.js"
|
||||
},
|
||||
"version": "1.1.7"
|
||||
"dependencies": {},
|
||||
"description": "Collects the full tree of processes from /proc"
|
||||
}
|
||||
|
||||
19
node_modules/pstree.remy/tests/fixtures/index.js
generated
vendored
19
node_modules/pstree.remy/tests/fixtures/index.js
generated
vendored
@@ -1,8 +1,13 @@
|
||||
const spawn = require('child_process').spawn;
|
||||
const sub = spawn(
|
||||
'sh',
|
||||
['-c', 'node -e "setInterval(() => console.log(`running`), 200)"'],
|
||||
{
|
||||
stdio: 'pipe',
|
||||
}
|
||||
);
|
||||
function run() {
|
||||
spawn(
|
||||
'sh',
|
||||
['-c', 'node -e "setInterval(() => console.log(`running`), 200)"'],
|
||||
{
|
||||
stdio: 'pipe',
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
var runCallCount = process.argv[2] || 1;
|
||||
for (var i = 0; i < runCallCount; i++) run();
|
||||
|
||||
31
node_modules/pstree.remy/tests/index.test.js
generated
vendored
31
node_modules/pstree.remy/tests/index.test.js
generated
vendored
@@ -6,35 +6,46 @@ const pstree = require('../');
|
||||
const { tree, pidsForTree, getStat } = require('../lib/utils');
|
||||
|
||||
if (process.platform !== 'darwin') {
|
||||
test('reads from /proc', async t => {
|
||||
test('reads from /proc', async (t) => {
|
||||
const ps = await getStat();
|
||||
t.ok(ps.split('\n').length > 1);
|
||||
});
|
||||
}
|
||||
|
||||
test('tree for live env', async t => {
|
||||
test('tree for live env', async (t) => {
|
||||
const pid = 4079;
|
||||
const fixture = readFile(__dirname + '/fixtures/out2', 'utf8');
|
||||
const ps = await tree(fixture);
|
||||
t.deepEqual(pidsForTree(ps, pid).map(_ => _.PID), ['4080']);
|
||||
t.deepEqual(
|
||||
pidsForTree(ps, pid).map((_) => _.PID),
|
||||
['4080']
|
||||
);
|
||||
});
|
||||
|
||||
test('can read full child process tree', t => {
|
||||
const sub = spawn('node', [`${__dirname}/fixtures/index.js`], {
|
||||
function testTree(t, runCallCount) {
|
||||
const sub = spawn('node', [`${__dirname}/fixtures/index.js`, runCallCount], {
|
||||
stdio: 'pipe',
|
||||
});
|
||||
setTimeout(() => {
|
||||
const pid = sub.pid;
|
||||
|
||||
pstree(pid, (error, children) => {
|
||||
children.concat([pid]).forEach(p => {
|
||||
pstree(pid, (error, pids) => {
|
||||
pids.concat([pid]).forEach((p) => {
|
||||
spawn('kill', ['-s', 'SIGTERM', p]);
|
||||
});
|
||||
|
||||
console.log(children);
|
||||
|
||||
t.equal(children.length, 2);
|
||||
// the fixture launches `sh` which launches node which is why we
|
||||
// are looking for two processes.
|
||||
// Important: IDKW but MacOS seems to skip the `sh` process. no idea.
|
||||
t.equal(pids.length, runCallCount * 2);
|
||||
t.end();
|
||||
});
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
test('can read full process tree', (t) => {
|
||||
testTree(t, 1);
|
||||
});
|
||||
test('can read full process tree with multiple processes', (t) => {
|
||||
testTree(t, 2);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user