Detailansicht verbessert

This commit is contained in:
Lukas Nowy
2019-02-13 00:36:21 +01:00
parent ff07d4ef0b
commit 87e7673513
1069 changed files with 105627 additions and 106 deletions

8
express-server/node_modules/pstree.remy/.travis.yml generated vendored Normal file
View File

@ -0,0 +1,8 @@
language: node_js
cache:
directories:
- ~/.npm
notifications:
email: false
node_js:
- '8'

32
express-server/node_modules/pstree.remy/lib/index.js generated vendored Normal file
View File

@ -0,0 +1,32 @@
const exec = require('child_process').exec;
const tree = require('./tree');
const utils = require('./utils');
var hasPS = true;
// discover if the OS has `ps`, and therefore can use psTree
exec('ps', error => {
module.exports.hasPS = hasPS = !error;
});
module.exports = function main(pid, callback) {
if (typeof pid === 'number') {
pid = pid.toString();
}
if (hasPS && !process.env.NO_PS) {
return tree(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));
};
if (!module.parent) {
module.exports(process.argv[2], (e, pids) => console.log(pids));
}
module.exports.hasPS = hasPS;

34
express-server/node_modules/pstree.remy/lib/tree.js generated vendored Normal file
View File

@ -0,0 +1,34 @@
const spawn = require('child_process').spawn;
module.exports = function(rootPid, callback) {
const tree = {};
var output = '';
// *nix
const ps = spawn('ps', ['-A', '-o', 'ppid,pid']);
ps.stdout.on('data', data => {
output += data.toString('ascii');
});
ps.on('close', () => {
try {
const res = output
.split('\n')
.slice(1)
.map(_ => _.trim())
.reduce((acc, line) => {
if (line.indexOf(rootPid + ' ') === 0) {
const pid = line.split(/\s+/).pop();
acc.push(parseInt(pid, 10));
rootPid = pid;
}
return acc;
}, []);
callback(null, res);
} catch (e) {
callback(e, null);
}
});
};

56
express-server/node_modules/pstree.remy/lib/utils.js generated vendored Normal file
View File

@ -0,0 +1,56 @@
const spawn = require('child_process').spawn;
module.exports = { tree, pidsForTree, getStat };
function getStat() {
return new Promise(resolve => {
const command = `ls /proc | grep -E '^[0-9]+$' | xargs -I{} cat /proc/{}/stat`;
const child = spawn('sh', ['-c', command], {
stdio: ['pipe', 'pipe', 'pipe'],
});
var res = '';
child.stdout.on('data', data => (res += data));
child.on('close', () => resolve(res));
});
}
function template(s) {
var stat = null;
// 'pid', 'comm', 'state', 'ppid', 'pgrp'
// %d (%s) %c %d %d
s.replace(
/(\d+) \((.*?)\)\s(.+?)\s(\d+)\s/g,
(all, PID, COMMAND, STAT, PPID) => {
stat = { PID, COMMAND, PPID, STAT };
}
);
return stat;
}
function tree(stats) {
const processes = stats
.split('\n')
.map(template)
.filter(Boolean);
return processes;
}
function pidsForTree(tree, pid) {
if (typeof pid === 'number') {
pid = pid.toString();
}
const parents = [pid];
const children = [];
tree.forEach(proc => {
if (parents.indexOf(proc.PPID) !== -1) {
parents.push(proc.PID);
children.push(proc);
}
});
return children;
}

50
express-server/node_modules/pstree.remy/package.json generated vendored Normal file
View File

@ -0,0 +1,50 @@
{
"_from": "pstree.remy@^1.1.6",
"_id": "pstree.remy@1.1.6",
"_inBundle": false,
"_integrity": "sha512-NdF35+QsqD7EgNEI5mkI/X+UwaxVEbQaz9f4IooEmMUv6ZPmlTQYGjBPJGgrlzNdjSvIy4MWMg6Q6vCgBO2K+w==",
"_location": "/pstree.remy",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "pstree.remy@^1.1.6",
"name": "pstree.remy",
"escapedName": "pstree.remy",
"rawSpec": "^1.1.6",
"saveSpec": null,
"fetchSpec": "^1.1.6"
},
"_requiredBy": [
"/nodemon"
],
"_resolved": "https://registry.npmjs.org/pstree.remy/-/pstree.remy-1.1.6.tgz",
"_shasum": "73a55aad9e2d95814927131fbf4dc1b62d259f47",
"_spec": "pstree.remy@^1.1.6",
"_where": "D:\\5CHITM\\Diplomarbeit\\SmartShopper\\SmartShopper\\express-server\\node_modules\\nodemon",
"author": {
"name": "Remy Sharp"
},
"bundleDependencies": false,
"dependencies": {},
"deprecated": false,
"description": "Collects the full tree of processes from /proc",
"devDependencies": {
"tap": "^11.0.0"
},
"directories": {
"test": "tests"
},
"keywords": [
"ps",
"pstree",
"ps tree"
],
"license": "MIT",
"main": "lib/index.js",
"name": "pstree.remy",
"scripts": {
"test": "tap tests/*.test.js"
},
"version": "1.1.6"
}

View File

@ -0,0 +1,8 @@
const spawn = require('child_process').spawn;
const sub = spawn(
'sh',
['-c', 'node -e "setInterval(() => console.log(`running`), 200)"'],
{
stdio: 'pipe',
}
);

View File

@ -0,0 +1,10 @@
1 (npm) S 0 1 1 34816 1 4210944 11112 0 0 0 45 8 0 0 20 0 10 0 330296 1089871872 11809 18446744073709551615 4194304 29343848 140726436642896 0 0 0 0 4096 2072112895 0 0 0 17 0 0 0 0 0 0 31441000 31537208 37314560 140726436650815 140726436650847 140726436650847 140726436650986 0
15 (sh) S 1 1 1 34816 1 4210688 115 0 0 0 0 0 0 0 20 0 1 0 330372 4399104 187 18446744073709551615 94374393548800 94374393655428 140722913272992 0 0 0 0 0 65538 0 0 0 17 0 0 0 0 0 0 94374395756424 94374395761184 94374404673536 140722913278928 140722913278959 140722913278959 140722913284080 0
16 (node) S 15 1 1 34816 1 4210688 6930 103 0 0 32 2 0 0 20 0 10 0 330373 1068478464 8412 18446744073709551615 4194304 29343848 140727228046064 0 0 0 0 4096 134300162 0 0 0 17 1 0 0 1 0 0 31441000 31537208 52584448 140727228050313 140727228050383 140727228050383 140727228055530 0
27 (sh) S 16 1 1 34816 1 4210688 111 0 0 0 0 0 0 0 20 0 1 0 330410 4399104 193 18446744073709551615 94848235986944 94848236093572 140727019991184 0 0 0 0 0 65538 0 0 0 17 1 0 0 0 0 0 94848238194568 94848238199328 94848261660672 140727019998122 140727019998165 140727019998165 140727020003312 0
28 (node) S 27 1 1 34816 1 4210688 3576 268 0 0 12 2 0 0 20 0 10 0 330411 930213888 6760 18446744073709551615 4194304 29343848 140726559664992 0 0 0 0 4096 134300162 0 0 0 17 1 0 0 0 0 0 31441000 31537208 32591872 140726559669117 140726559669199 140726559669199 140726559674346 0
39 (node) S 28 1 1 34816 1 4210688 47517 0 0 0 151 9 0 0 20 0 6 0 330427 985739264 31859 18446744073709551615 4194304 29343848 140737324503920 0 0 0 0 4096 134234626 0 0 0 17 0 0 0 0 0 0 31441000 31537208 51585024 140737324510060 140737324510159 140737324510159 140737324515306 0
45 (bash) S 0 45 45 34817 50 4210944 752 256 0 0 2 0 0 0 20 0 1 0 331039 18628608 789 18446744073709551615 4194304 5242124 140724425887696 0 0 0 65536 3670020 1266777851 0 0 0 17 1 0 0 0 0 0 7341384 7388228 30310400 140724425891678 140724425891683 140724425891683 140724425891822 0
cat: /proc/50/stat: No such file or directory
cat: /proc/51/stat: No such file or directory
52 (xargs) S 45 50 45 34817 50 4210688 179 661 0 0 0 0 0 0 20 0 1 0 331544 4608000 346 18446744073709551615 94587588550656 94587588614028 140735223856048 0 0 0 0 0 2560 0 0 0 17 1 0 0 0 0 0 94587590711464 94587590713504 94587603169280 140735223861006 140735223861035 140735223861035 140735223861225 0

View File

@ -0,0 +1,29 @@
cat: /proc/4087/stat: No such file or directory
cat: /proc/4088/stat: No such file or directory
1 (init) S 0 1 1 0 -1 4210944 9227 55994 29 319 7 5 68 16 20 0 1 0 1286281 33660928 855 18446744073709551615 1 1 0 0 0 0 0 4096 536962595 0 0 0 17 4 0 0 3 0 0 0 0 0 0 0 0 0 0
1032 (ntpd) S 1 1032 1032 0 -1 4211008 178 0 1 0 0 0 0 0 20 0 1 0 1287033 25743360 1058 18446744073709551615 1 1 0 0 0 0 0 4096 27207 0 0 0 17 4 0 0 0 0 0 0 0 0 0 0 0 0 0
126 (irqbalance) S 1 126 126 0 -1 1077952832 1217 0 0 0 1 6 0 0 20 0 1 0 1286749 20189184 647 18446744073709551615 1 1 0 0 0 0 0 0 3 0 0 0 17 4 0 0 0 0 0 0 0 0 0 0 0 0 0
181 (mysqld) S 1 181 181 0 -1 4210944 6399 0 46 0 8 6 0 0 20 0 22 0 1286761 748453888 14476 18446744073709551615 1 1 0 0 0 0 552967 4096 26345 0 0 0 17 4 0 0 10 0 0 0 0 0 0 0 0 0 0
194 (memcached) S 1 187 187 0 -1 4210944 252 0 4 0 0 0 0 0 20 0 6 0 1286766 333221888 648 18446744073709551615 1 1 0 0 0 0 0 4096 2 0 0 0 17 4 0 0 0 0 0 0 0 0 0 0 0 0 0
243 (dbus-daemon) S 1 243 243 0 -1 4211008 67 0 0 0 0 0 0 0 20 0 1 0 1286779 40087552 598 18446744073709551615 1 1 0 0 0 0 0 0 16385 0 0 0 17 4 0 0 0 0 0 0 0 0 0 0 0 0 0
254 (rsyslogd) S 1 254 254 0 -1 4211008 107 0 0 0 2 2 0 0 20 0 3 0 1286782 186601472 696 18446744073709551615 1 1 0 0 0 0 0 16781830 1133601 0 0 0 17 5 0 0 0 0 0 0 0 0 0 0 0 0 0
265 (systemd-logind) S 1 265 265 0 -1 4210944 276 0 2 0 0 0 0 0 20 0 1 0 1286786 35880960 720 18446744073709551615 1 1 0 0 0 0 0 0 0 0 0 0 17 4 0 0 0 0 0 0 0 0 0 0 0 0 0
333 (postgres) S 1 303 303 0 -1 4210688 3169 3466 15 18 0 1 1 1 20 0 1 0 1286817 156073984 5002 18446744073709551615 1 1 0 0 0 0 0 19935232 84487 0 0 0 17 5 0 0 1 0 0 0 0 0 0 0 0 0 0
359 (postgres) S 333 359 359 0 -1 4210752 90 0 0 0 0 0 0 0 20 0 1 0 1286822 156073984 827 18446744073709551615 1 1 0 0 0 0 0 16805888 2567 0 0 0 17 4 0 0 0 0 0 0 0 0 0 0 0 0 0
360 (postgres) S 333 360 360 0 -1 4210752 119 0 0 0 0 0 0 0 20 0 1 0 1286822 156073984 827 18446744073709551615 1 1 0 0 0 0 0 16791554 16901 0 0 0 17 4 0 0 0 0 0 0 0 0 0 0 0 0 0
361 (postgres) S 333 361 361 0 -1 4210752 87 0 0 0 0 0 0 0 20 0 1 0 1286822 156073984 827 18446744073709551615 1 1 0 0 0 0 0 16791552 16903 0 0 0 17 4 0 0 0 0 0 0 0 0 0 0 0 0 0
362 (postgres) S 333 362 362 0 -1 4210752 292 0 3 0 0 0 0 0 20 0 1 0 1286822 156930048 1373 18446744073709551615 1 1 0 0 0 0 0 19927040 27271 0 0 0 17 5 0 0 0 0 0 0 0 0 0 0 0 0 0
363 (postgres) S 333 363 363 0 -1 4210752 82 0 0 0 0 0 0 0 20 0 1 0 1286822 115924992 887 18446744073709551615 1 1 0 0 0 0 0 16808450 5 0 0 0 17 5 0 0 0 0 0 0 0 0 0 0 0 0 0
4050 (npm) S 50 50 50 34817 50 4210688 5109 0 0 0 36 3 0 0 20 0 10 0 1292968 738025472 10051 18446744073709551615 4194304 33165900 140723623956256 0 0 0 0 4096 134300162 0 0 0 17 4 0 0 0 0 0 35263056 35370992 48369664 140723623964237 140723623964294 140723623964294 140723623968712 0
4060 (sh) S 4050 50 50 34817 50 4210688 121 0 0 0 0 0 0 0 20 0 1 0 1293007 4579328 174 18446744073709551615 94347643936768 94347644049516 140735136055088 0 0 0 0 0 65538 1 0 0 17 5 0 0 0 0 0 94347646148008 94347646153216 94347660038144 140735136063095 140735136063129 140735136063129 140735136071664 0
4061 (node) S 4060 50 50 34817 50 4210688 6501 0 0 0 42 2 0 0 20 0 6 0 1293008 705769472 10211 18446744073709551615 4194304 33165900 140730532686288 0 0 0 0 4096 2072111671 0 0 0 17 5 0 0 0 0 0 35263056 35370992 45867008 140730532695579 140730532695657 140730532695657 140730532704200 0
4067 (node) S 4061 50 50 34817 50 4210688 6746 221 0 0 38 3 0 0 20 0 10 0 1293051 738910208 10527 18446744073709551615 4194304 33165900 140724824971632 0 0 0 0 4096 2072111671 0 0 0 17 4 0 0 0 0 0 35263056 35370992 68595712 140724824980995 140724824981063 140724824981063 140724824989640 0
4079 (sh) S 4067 50 50 34817 50 4210688 118 0 0 0 0 0 0 0 20 0 1 0 1293092 4579328 194 18446744073709551615 94573702131712 94573702244460 140724712357120 0 0 0 0 0 65538 1 0 0 17 4 0 0 0 0 0 94573704342952 94573704348160 94573718511616 140724712361487 140724712361583 140724712361583 140724712370160 0
4080 (node) S 4079 50 50 34817 50 4210688 2428 0 0 0 8 1 0 0 20 0 6 0 1293093 693059584 7251 18446744073709551615 4194304 33165900 140726023392816 0 0 0 0 4096 134234626 0 0 0 17 5 0 0 0 0 0 35263056 35370992 55226368 140726023396847 140726023396935 140726023396935 140726023405512 0
4086 (sh) S 4067 50 50 34817 50 4210688 131 244 0 0 0 0 0 0 20 0 1 0 1293143 4579328 200 18446744073709551615 94347550273536 94347550386284 140737219399136 0 0 0 0 0 65538 1 0 0 17 5 0 0 0 0 0 94347552484776 94347552489984 94347554299904 140737219403308 140737219403375 140737219403375 140737219411952 0
4089 (xargs) S 4086 50 50 34817 50 4210688 333 1924 0 0 0 0 0 0 20 0 1 0 1293143 17600512 477 18446744073709551615 4194304 4232732 140721633759248 0 0 0 0 0 0 1 0 0 17 5 0 0 0 0 0 6331920 6332980 32182272 140721633762891 140721633762920 140721633762920 140721633771497 0
50 (bash) S 0 50 50 34817 50 4210944 43914 1032463 9 705 44 21 4213 818 20 0 1 0 1286336 42266624 3599 18446744073709551615 4194304 5173404 140732749083280 0 0 0 65536 4 1132560123 1 0 0 17 4 0 0 410 0 0 7273968 7310504 21196800 140732749086490 140732749086517 140732749086517 140732749086702 0
79 (acpid) S 1 79 79 0 -1 4210752 46 0 0 0 0 0 0 0 20 0 1 0 1286717 4493312 407 18446744073709551615 1 1 0 0 0 0 0 4096 16391 0 0 0 17 5 0 0 0 0 0 0 0 0 0 0 0 0 0
83 (sshd) S 1 83 83 0 -1 4210944 354 0 27 0 0 0 0 0 20 0 1 0 1286718 62873600 1290 18446744073709551615 1 1 0 0 0 0 0 4096 81925 0 0 0 17 4 0 0 30 0 0 0 0 0 0 0 0 0 0
94 (cron) S 1 94 94 0 -1 1077952576 103 449 0 1 0 0 0 0 20 0 1 0 1286743 24240128 559 18446744073709551615 1 1 0 0 0 0 0 0 65537 0 0 0 17 4 0 0 0 0 0 0 0 0 0 0 0 0 0
95 (atd) S 1 95 95 0 -1 1077952576 28 0 0 0 0 0 0 0 20 0 1 0 1286743 19615744 41 18446744073709551615 1 1 0 0 0 0 0 0 81923 0 0 0 17 4 0 0 0 0 0 0 0 0 0 0 0 0 0

View File

@ -0,0 +1,40 @@
const tap = require('tap');
const test = tap.test;
const readFile = require('fs').readFileSync;
const spawn = require('child_process').spawn;
const pstree = require('../');
const { tree, pidsForTree, getStat } = require('../lib/utils');
if (process.platform !== 'darwin') {
test('reads from /proc', async t => {
const ps = await getStat();
t.ok(ps.split('\n').length > 1);
});
}
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']);
});
test('can read full child process tree', t => {
const sub = spawn('node', [`${__dirname}/fixtures/index.js`], {
stdio: 'pipe',
});
setTimeout(() => {
const pid = sub.pid;
pstree(pid, (error, children) => {
children.concat([pid]).forEach(p => {
spawn('kill', ['-s', 'SIGTERM', p]);
});
console.log(children);
t.equal(children.length, 2);
t.end();
});
}, 1000);
});