main
|
Last change
on this file was 81bc7da, checked in by Klimentina Efremova <klimentina08642@…>, 3 months ago |
|
Initial commit
|
-
Property mode
set to
100644
|
|
File size:
800 bytes
|
| Line | |
|---|
| 1 | const exec = require('child_process').exec;
|
|---|
| 2 | const tree = require('./tree');
|
|---|
| 3 | const utils = require('./utils');
|
|---|
| 4 | var hasPS = true;
|
|---|
| 5 |
|
|---|
| 6 | // discover if the OS has `ps`, and therefore can use psTree
|
|---|
| 7 | exec('ps', (error) => {
|
|---|
| 8 | module.exports.hasPS = hasPS = !error;
|
|---|
| 9 | });
|
|---|
| 10 |
|
|---|
| 11 | module.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 |
|
|---|
| 33 | if (!module.parent) {
|
|---|
| 34 | module.exports(process.argv[2], (e, pids) => console.log(pids));
|
|---|
| 35 | }
|
|---|
| 36 |
|
|---|
| 37 | module.exports.hasPS = hasPS;
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.