source: node_modules/pstree.remy/lib/index.js@ 2d1ec46

main
Last change on this file since 2d1ec46 was 81bc7da, checked in by Klimentina Efremova <klimentina08642@…>, 3 months ago

Initial commit

  • Property mode set to 100644
File size: 800 bytes
RevLine 
[81bc7da]1const exec = require('child_process').exec;
2const tree = require('./tree');
3const utils = require('./utils');
4var hasPS = true;
5
6// discover if the OS has `ps`, and therefore can use psTree
7exec('ps', (error) => {
8 module.exports.hasPS = hasPS = !error;
9});
10
11module.exports = function main(pid, callback) {
12 if (typeof pid === 'number') {
13 pid = pid.toString();
14 }
15
16 if (hasPS && !process.env.NO_PS) {
17 return tree(pid, callback);
18 }
19
20 utils
21 .getStat()
22 .then(utils.tree)
23 .then((tree) => utils.pidsForTree(tree, pid))
24 .then((res) =>
25 callback(
26 null,
27 res.map((p) => p.PID)
28 )
29 )
30 .catch((error) => callback(error));
31};
32
33if (!module.parent) {
34 module.exports(process.argv[2], (e, pids) => console.log(pids));
35}
36
37module.exports.hasPS = hasPS;
Note: See TracBrowser for help on using the repository browser.