summaryrefslogtreecommitdiffstats
path: root/node_modules/pidtree
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/pidtree')
-rwxr-xr-xnode_modules/pidtree/bin/pidtree.js128
-rw-r--r--node_modules/pidtree/index.js46
-rw-r--r--node_modules/pidtree/lib/bin.js49
-rw-r--r--node_modules/pidtree/lib/get.js40
-rw-r--r--node_modules/pidtree/lib/pidtree.js104
-rw-r--r--node_modules/pidtree/lib/ps.js47
-rw-r--r--node_modules/pidtree/lib/wmic.js49
-rw-r--r--node_modules/pidtree/license21
-rw-r--r--node_modules/pidtree/package.json123
-rw-r--r--node_modules/pidtree/readme.md189
10 files changed, 796 insertions, 0 deletions
diff --git a/node_modules/pidtree/bin/pidtree.js b/node_modules/pidtree/bin/pidtree.js
new file mode 100755
index 0000000..542876e
--- /dev/null
+++ b/node_modules/pidtree/bin/pidtree.js
@@ -0,0 +1,128 @@
+#!/usr/bin/env node
+
+'use strict';
+
+var os = require('os');
+var pidtree = require('..');
+
+// The method startsWith is not defined on string objects in node 0.10
+// eslint-disable-next-line no-extend-native
+String.prototype.startsWith = function(suffix) {
+ return this.substring(0, suffix.length) === suffix;
+};
+
+function help() {
+ var help =
+ ' Usage\n' +
+ ' $ pidtree <ppid>\n' +
+ '\n' +
+ 'Options\n' +
+ ' --list To print the pids as a list.\n' +
+ '\n' +
+ 'Examples\n' +
+ ' $ pidtree\n' +
+ ' $ pidtree --list\n' +
+ ' $ pidtree 1\n' +
+ ' $ pidtree 1 --list\n';
+ console.log(help);
+}
+
+function list(ppid) {
+ pidtree(ppid === undefined ? -1 : ppid, function(err, list) {
+ if (err) {
+ console.error(err.message);
+ return;
+ }
+
+ console.log(list.join(os.EOL));
+ });
+}
+
+function tree(ppid) {
+ pidtree(ppid, {advanced: true}, function(err, list) {
+ if (err) {
+ console.error(err.message);
+ return;
+ }
+
+ var parents = {}; // Hash Map of parents
+ var tree = {}; // Adiacency Hash Map
+ while (list.length > 0) {
+ var element = list.pop();
+ if (tree[element.ppid]) {
+ tree[element.ppid].push(element.pid);
+ } else {
+ tree[element.ppid] = [element.pid];
+ }
+
+ if (ppid === -1) {
+ parents[element.pid] = element.ppid;
+ }
+ }
+
+ var roots = [ppid];
+ if (ppid === -1) {
+ // Get all the roots
+ roots = Object.keys(tree).filter(function(node) {
+ return parents[node] === undefined;
+ });
+ }
+
+ roots.forEach(function(root) {
+ print(tree, root);
+ });
+ });
+
+ function print(tree, start) {
+ function printBranch(node, branch) {
+ var isGraphHead = branch.length === 0;
+ var children = tree[node] || [];
+
+ var branchHead = '';
+ if (!isGraphHead) {
+ branchHead = children.length > 0 ? '┬ ' : '─ ';
+ }
+
+ console.log(branch + branchHead + node);
+
+ var baseBranch = branch;
+ if (!isGraphHead) {
+ var isChildOfLastBranch = branch.slice(-2) === '└─';
+ baseBranch = branch.slice(0, -2) + (isChildOfLastBranch ? ' ' : '| ');
+ }
+
+ var nextBranch = baseBranch + '├─';
+ var lastBranch = baseBranch + '└─';
+ children.forEach(function(child, index) {
+ printBranch(
+ child,
+ children.length - 1 === index ? lastBranch : nextBranch
+ );
+ });
+ }
+
+ printBranch(start, '');
+ }
+}
+
+function run() {
+ var flag;
+ var ppid;
+ for (var i = 2; i < process.argv.length; i++) {
+ if (process.argv[i].startsWith('--')) {
+ flag = process.argv[i];
+ } else {
+ ppid = process.argv[i];
+ }
+ }
+
+ if (ppid === undefined) {
+ ppid = -1;
+ }
+
+ if (flag === '--list') list(ppid);
+ else if (flag === undefined) tree(ppid);
+ else help();
+}
+
+run();
diff --git a/node_modules/pidtree/index.js b/node_modules/pidtree/index.js
new file mode 100644
index 0000000..2e2a92e
--- /dev/null
+++ b/node_modules/pidtree/index.js
@@ -0,0 +1,46 @@
+'use strict';
+
+function pify(fn, arg1, arg2) {
+ return new Promise(function(resolve, reject) {
+ fn(arg1, arg2, function(err, data) {
+ if (err) return reject(err);
+ resolve(data);
+ });
+ });
+}
+
+// The method startsWith is not defined on string objects in node 0.10
+// eslint-disable-next-line no-extend-native
+String.prototype.startsWith = function(suffix) {
+ return this.substring(0, suffix.length) === suffix;
+};
+
+var pidtree = require('./lib/pidtree');
+
+/**
+ * Get the list of children pids of the given pid.
+ * @public
+ * @param {Number|String} pid A PID. If -1 will return all the pids.
+ * @param {Object} [options] Optional options object.
+ * @param {Boolean} [options.root=false] Include the provided PID in the list.
+ * @param {Boolean} [options.advanced=false] Returns a list of objects in the
+ * format {pid: X, ppid: Y}.
+ * @param {Function} [callback=undefined] Called when the list is ready. If not
+ * provided a promise is returned instead.
+ * @returns {Promise.<Object[]>} Only when the callback is not provided.
+ */
+function list(pid, options, callback) {
+ if (typeof options === 'function') {
+ callback = options;
+ options = undefined;
+ }
+
+ if (typeof callback === 'function') {
+ pidtree(pid, options, callback);
+ return;
+ }
+
+ return pify(pidtree, pid, options);
+}
+
+module.exports = list;
diff --git a/node_modules/pidtree/lib/bin.js b/node_modules/pidtree/lib/bin.js
new file mode 100644
index 0000000..1e917cc
--- /dev/null
+++ b/node_modules/pidtree/lib/bin.js
@@ -0,0 +1,49 @@
+'use strict';
+
+var spawn = require('child_process').spawn;
+
+/**
+ * Spawn a binary and read its stdout.
+ * @param {String} cmd The name of the binary to spawn.
+ * @param {String[]} args The arguments for the binary.
+ * @param {Object} [options] Optional option for the spawn function.
+ * @param {Function} done(err, stdout)
+ */
+function run(cmd, args, options, done) {
+ if (typeof options === 'function') {
+ done = options;
+ options = undefined;
+ }
+
+ var executed = false;
+ var ch = spawn(cmd, args, options);
+ var stdout = '';
+ var stderr = '';
+
+ ch.stdout.on('data', function(d) {
+ stdout += d.toString();
+ });
+
+ ch.stderr.on('data', function(d) {
+ stderr += d.toString();
+ });
+
+ ch.on('error', function(err) {
+ if (executed) return;
+ executed = true;
+ done(new Error(err));
+ });
+
+ ch.on('close', function(code) {
+ if (executed) return;
+ executed = true;
+
+ if (stderr) {
+ return done(new Error(stderr));
+ }
+
+ done(null, stdout, code);
+ });
+}
+
+module.exports = run;
diff --git a/node_modules/pidtree/lib/get.js b/node_modules/pidtree/lib/get.js
new file mode 100644
index 0000000..1793d54
--- /dev/null
+++ b/node_modules/pidtree/lib/get.js
@@ -0,0 +1,40 @@
+'use strict';
+
+var os = require('os');
+
+var platformToMethod = {
+ darwin: 'ps',
+ sunos: 'ps',
+ freebsd: 'ps',
+ netbsd: 'ps',
+ win: 'wmic',
+ linux: 'ps',
+ aix: 'ps'
+};
+
+var platform = os.platform();
+if (platform.startsWith('win')) {
+ platform = 'win';
+}
+
+var file = platformToMethod[platform];
+
+/**
+ * Gets the list of all the pids of the system.
+ * @param {Function} callback Called when the list is ready.
+ */
+function get(callback) {
+ if (file === undefined) {
+ callback(
+ new Error(
+ os.platform() +
+ ' is not supported yet, please open an issue (https://github.com/simonepri/pidtree)'
+ )
+ );
+ }
+
+ var list = require('./' + file);
+ list(callback);
+}
+
+module.exports = get;
diff --git a/node_modules/pidtree/lib/pidtree.js b/node_modules/pidtree/lib/pidtree.js
new file mode 100644
index 0000000..52986b5
--- /dev/null
+++ b/node_modules/pidtree/lib/pidtree.js
@@ -0,0 +1,104 @@
+'use strict';
+
+var getAll = require('./get');
+
+/**
+ * Get the list of children and grandchildren pids of the given PID.
+ * @param {Number|String} PID A PID. If -1 will return all the pids.
+ * @param {Object} [options] Optional options object.
+ * @param {Boolean} [options.root=false] Include the provided PID in the list.
+ * @param {Boolean} [options.advanced=false] Returns a list of objects in the
+ * format {pid: X, ppid: Y}.
+ * @param {Function} callback(err, list) Called when the list is ready.
+ */
+function list(PID, options, callback) {
+ if (typeof options === 'function') {
+ callback = options;
+ options = {};
+ }
+
+ if (typeof options !== 'object') {
+ options = {};
+ }
+
+ PID = parseInt(PID, 10);
+ if (isNaN(PID) || PID < -1) {
+ callback(new TypeError('The pid provided is invalid'));
+ return;
+ }
+
+ getAll(function(err, list) {
+ if (err) {
+ callback(err);
+ return;
+ }
+
+ // If the user wants the whole list just return it
+ if (PID === -1) {
+ for (var i = 0; i < list.length; i++) {
+ list[i] = options.advanced
+ ? {ppid: list[i][0], pid: list[i][1]}
+ : (list[i] = list[i][1]);
+ }
+
+ callback(null, list);
+ return;
+ }
+
+ var root;
+ for (var l = 0; l < list.length; l++) {
+ if (list[l][1] === PID) {
+ root = options.advanced ? {ppid: list[l][0], pid: PID} : PID;
+ break;
+ }
+
+ if (list[l][0] === PID) {
+ root = options.advanced ? {pid: PID} : PID; // Special pids like 0 on *nix
+ }
+ }
+
+ if (!root) {
+ callback(new Error('No maching pid found'));
+ return;
+ }
+
+ // Build the adiacency Hash Map (pid -> [children of pid])
+ var tree = {};
+ while (list.length > 0) {
+ var element = list.pop();
+ if (tree[element[0]]) {
+ tree[element[0]].push(element[1]);
+ } else {
+ tree[element[0]] = [element[1]];
+ }
+ }
+
+ // Starting by the PID provided by the user, traverse the tree using the
+ // adiacency Hash Map until the whole subtree is visited.
+ // Each pid encountered while visiting is added to the pids array.
+ var idx = 0;
+ var pids = [root];
+ while (idx < pids.length) {
+ var curpid = options.advanced ? pids[idx++].pid : pids[idx++];
+ if (!tree[curpid]) continue;
+ var length = tree[curpid].length;
+ for (var j = 0; j < length; j++) {
+ pids.push(
+ options.advanced
+ ? {ppid: curpid, pid: tree[curpid][j]}
+ : tree[curpid][j]
+ );
+ }
+
+ delete tree[curpid];
+ }
+
+ if (!options.root) {
+ pids.shift(); // Remove root
+ }
+
+ callback(null, pids);
+ });
+}
+
+module.exports = list;
diff --git a/node_modules/pidtree/lib/ps.js b/node_modules/pidtree/lib/ps.js
new file mode 100644
index 0000000..6d9bb5f
--- /dev/null
+++ b/node_modules/pidtree/lib/ps.js
@@ -0,0 +1,47 @@
+'use strict';
+
+var os = require('os');
+var bin = require('./bin');
+
+/**
+ * Gets the list of all the pids of the system through the ps command.
+ * @param {Function} callback(err, list)
+ */
+function ps(callback) {
+ var args = ['-A', '-o', 'ppid,pid'];
+
+ bin('ps', args, function(err, stdout, code) {
+ if (err) return callback(err);
+ if (code !== 0) {
+ return callback(new Error('pidtree ps command exited with code ' + code));
+ }
+
+ // Example of stdout
+ //
+ // PPID PID
+ // 1 430
+ // 430 432
+ // 1 727
+ // 1 7166
+
+ try {
+ stdout = stdout.split(os.EOL);
+
+ var list = [];
+ for (var i = 1; i < stdout.length; i++) {
+ stdout[i] = stdout[i].trim();
+ if (!stdout[i]) continue;
+ stdout[i] = stdout[i].split(/\s+/);
+ stdout[i][0] = parseInt(stdout[i][0], 10); // PPID
+ stdout[i][1] = parseInt(stdout[i][1], 10); // PID
+ list.push(stdout[i]);
+ }
+
+ callback(null, list);
+ } catch (error) {
+ callback(error);
+ }
+ });
+}
+
+module.exports = ps;
diff --git a/node_modules/pidtree/lib/wmic.js b/node_modules/pidtree/lib/wmic.js
new file mode 100644
index 0000000..0361728
--- /dev/null
+++ b/node_modules/pidtree/lib/wmic.js
@@ -0,0 +1,49 @@
+'use strict';
+
+var os = require('os');
+var bin = require('./bin');
+
+/**
+ * Gets the list of all the pids of the system through the wmic command.
+ * @param {Function} callback(err, list)
+ */
+function wmic(callback) {
+ var args = ['PROCESS', 'get', 'ParentProcessId,ProcessId'];
+ var options = {windowsHide: true, windowsVerbatimArguments: true};
+ bin('wmic', args, options, function(err, stdout, code) {
+ if (err) {
+ callback(err);
+ return;
+ }
+
+ if (code !== 0) {
+ callback(new Error('pidtree wmic command exited with code ' + code));
+ return;
+ }
+
+ // Example of stdout
+ //
+ // ParentProcessId ProcessId
+ // 0 777
+
+ try {
+ stdout = stdout.split(os.EOL);
+
+ var list = [];
+ for (var i = 1; i < stdout.length; i++) {
+ stdout[i] = stdout[i].trim();
+ if (!stdout[i]) continue;
+ stdout[i] = stdout[i].split(/\s+/);
+ stdout[i][0] = parseInt(stdout[i][0], 10); // PPID
+ stdout[i][1] = parseInt(stdout[i][1], 10); // PID
+ list.push(stdout[i]);
+ }
+
+ callback(null, list);
+ } catch (error) {
+ callback(error);
+ }
+ });
+}
+
+module.exports = wmic;
diff --git a/node_modules/pidtree/license b/node_modules/pidtree/license
new file mode 100644
index 0000000..5582304
--- /dev/null
+++ b/node_modules/pidtree/license
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2018 Simone Primarosa
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/node_modules/pidtree/package.json b/node_modules/pidtree/package.json
new file mode 100644
index 0000000..282e93c
--- /dev/null
+++ b/node_modules/pidtree/package.json
@@ -0,0 +1,123 @@
+{
+ "_from": "pidtree@^0.3.0",
+ "_id": "pidtree@0.3.1",
+ "_inBundle": false,
+ "_integrity": "sha512-qQbW94hLHEqCg7nhby4yRC7G2+jYHY4Rguc2bjw7Uug4GIJuu1tvf2uHaZv5Q8zdt+WKJ6qK1FOI6amaWUo5FA==",
+ "_location": "/pidtree",
+ "_phantomChildren": {},
+ "_requested": {
+ "type": "range",
+ "registry": true,
+ "raw": "pidtree@^0.3.0",
+ "name": "pidtree",
+ "escapedName": "pidtree",
+ "rawSpec": "^0.3.0",
+ "saveSpec": null,
+ "fetchSpec": "^0.3.0"
+ },
+ "_requiredBy": [
+ "/npm-run-all"
+ ],
+ "_resolved": "https://registry.npmjs.org/pidtree/-/pidtree-0.3.1.tgz",
+ "_shasum": "ef09ac2cc0533df1f3250ccf2c4d366b0d12114a",
+ "_spec": "pidtree@^0.3.0",
+ "_where": "/home/pruss/Dev/3-minute-website/node_modules/npm-run-all",
+ "author": {
+ "name": "Simone Primarosa",
+ "email": "simonepri@outlook.com",
+ "url": "https://github.com/simonepri"
+ },
+ "ava": {
+ "verbose": true
+ },
+ "bin": {
+ "pidtree": "bin/pidtree.js"
+ },
+ "bugs": {
+ "url": "https://github.com/simonepri/pidtree/issues",
+ "email": "simonepri@outlook.com"
+ },
+ "bundleDependencies": false,
+ "contributors": [
+ {
+ "name": "Simone Primarosa",
+ "email": "simonepri@outlook.com",
+ "url": "https://github.com/simonepri"
+ }
+ ],
+ "deprecated": false,
+ "description": "Cross platform children list of a PID",
+ "devDependencies": {
+ "ava": "~0.25.0",
+ "codecov": "^3.6.5",
+ "mockery": "^2.1.0",
+ "np": "^2.20.1",
+ "npm-check": "^5.9.2",
+ "nyc": "^11.6.0",
+ "pify": "^3.0.0",
+ "string-to-stream": "^1.1.0",
+ "through": "^2.3.8",
+ "time-span": "^2.0.0",
+ "tree-kill": "^1.1.0",
+ "xo": "~0.20.3"
+ },
+ "engines": {
+ "node": ">=0.10"
+ },
+ "files": [
+ "bin",
+ "lib",
+ "index.js"
+ ],
+ "homepage": "http://github.com/simonepri/pidtree#readme",
+ "keywords": [
+ "ps-tree",
+ "ps",
+ "tree",
+ "ppid",
+ "pid",
+ "pidtree",
+ "pgrep",
+ "list",
+ "all",
+ "system",
+ "process",
+ "processes"
+ ],
+ "license": "MIT",
+ "main": "index.js",
+ "name": "pidtree",
+ "nyc": {
+ "reporter": [
+ "lcovonly",
+ "text"
+ ]
+ },
+ "repository": {
+ "type": "git",
+ "url": "git+https://github.com/simonepri/pidtree.git"
+ },
+ "scripts": {
+ "bench": "ava -m \"*benchmark*\"",
+ "coverage": "codecov",
+ "lint": "xo",
+ "release": "np",
+ "start": "node ./bin/pidtree.js",
+ "test": "nyc ava -m \"!*benchmark*\"",
+ "update": "npm-check -u"
+ },
+ "version": "0.3.1",
+ "xo": {
+ "prettier": true,
+ "space": true,
+ "rules": {
+ "prefer-destructuring": 0,
+ "prefer-arrow-callback": 0,
+ "no-var": 0,
+ "object-shorthand": 0,
+ "unicorn/no-for-loop": 0,
+ "unicorn/prefer-string-slice": 0,
+ "unicorn/string-content": 0
+ }
+ }
+}
diff --git a/node_modules/pidtree/readme.md b/node_modules/pidtree/readme.md
new file mode 100644
index 0000000..3608016
--- /dev/null
+++ b/node_modules/pidtree/readme.md
@@ -0,0 +1,189 @@
+<h1 align="center">
+ <b>pidtree</b>
+</h1>
+<p align="center">
+ <!-- CI - TravisCI -->
+ <a href="https://travis-ci.org/simonepri/pidtree">
+ <img src="https://img.shields.io/travis/simonepri/pidtree/master.svg?label=MacOS%20%26%20Linux" alt="Mac/Linux Build Status" />
+ </a>
+ <!-- CI - AppVeyor -->
+ <a href="https://ci.appveyor.com/project/simonepri/pidtree">
+ <img src="https://img.shields.io/appveyor/ci/simonepri/pidtree/master.svg?label=Windows" alt="Windows Build status" />
+ </a>
+ <!-- Coverage - Codecov -->
+ <a href="https://codecov.io/gh/simonepri/pidtree">
+ <img src="https://img.shields.io/codecov/c/github/simonepri/pidtree/master.svg" alt="Codecov Coverage report" />
+ </a>
+ <!-- DM - Snyk -->
+ <a href="https://snyk.io/test/github/simonepri/pidtree?targetFile=package.json">
+ <img src="https://snyk.io/test/github/simonepri/pidtree/badge.svg?targetFile=package.json" alt="Known Vulnerabilities" />
+ </a>
+ <!-- DM - David -->
+ <a href="https://david-dm.org/simonepri/pidtree">
+ <img src="https://david-dm.org/simonepri/pidtree/status.svg" alt="Dependency Status" />
+ </a>
+
+ <br/>
+
+ <!-- Code Style - XO-Prettier -->
+ <a href="https://github.com/xojs/xo">
+ <img src="https://img.shields.io/badge/code_style-XO+Prettier-5ed9c7.svg" alt="XO Code Style used" />
+ </a>
+ <!-- Test Runner - AVA -->
+ <a href="https://github.com/avajs/ava">
+ <img src="https://img.shields.io/badge/test_runner-AVA-fb3170.svg" alt="AVA Test Runner used" />
+ </a>
+ <!-- Test Coverage - Istanbul -->
+ <a href="https://github.com/istanbuljs/nyc">
+ <img src="https://img.shields.io/badge/test_coverage-NYC-fec606.svg" alt="Istanbul Test Coverage used" />
+ </a>
+ <!-- Init - ni -->
+ <a href="https://github.com/simonepri/ni">
+ <img src="https://img.shields.io/badge/initialized_with-ni-e74c3c.svg" alt="NI Scaffolding System used" />
+ </a>
+ <!-- Release - np -->
+ <a href="https://github.com/sindresorhus/np">
+ <img src="https://img.shields.io/badge/released_with-np-6c8784.svg" alt="NP Release System used" />
+ </a>
+
+ <br/>
+
+ <!-- Version - npm -->
+ <a href="https://www.npmjs.com/package/pidtree">
+ <img src="https://img.shields.io/npm/v/pidtree.svg" alt="Latest version on npm" />
+ </a>
+ <!-- License - MIT -->
+ <a href="https://github.com/simonepri/pidtree/tree/master/license">
+ <img src="https://img.shields.io/github/license/simonepri/pidtree.svg" alt="Project license" />
+ </a>
+</p>
+<p align="center">
+ 🚸 Cross platform children list of a PID.
+
+ <br/>
+
+ <sub>
+ Coded with ❤️ by <a href="#authors">Simone Primarosa</a>.
+ </sub>
+</p>
+
+## Synopsis
+
+This package is really similar to [ps-tree][gh:ps-tree] but is faster, safer and
+provides sub-children results.
+Furthermore ps-tree is [unmaintained][gh:ps-tree-um].
+
+Uuh, and a fancy [CLI](#cli) is also available!
+
+## Usage
+
+```js
+var pidtree = require('pidtree')
+
+// Get childs of current process
+pidtree(process.pid, function (err, pids) {
+ console.log(pids)
+ // => []
+})
+
+// Include the given pid in the result array
+pidtree(process.pid, {root: true}, function (err, pids) {
+ console.log(pids)
+ // => [727]
+})
+
+// Get all the processes of the System (-1 is a special value of this package)
+pidtree(-1, function (err, pids) {
+ console.log(pids)
+ // => [530, 42, ..., 41241]
+})
+
+// Include PPID in the results
+pidtree(1, {advanced: true}, function (err, pids) {
+ console.log(pids)
+ // => [{ppid: 1, pid: 530}, {ppid: 1, pid: 42}, ..., {ppid: 1, pid: 41241}]
+})
+
+// If no callback is given it returns a promise instead
+const pids = await pidtree(1)
+console.log(pids)
+// => [141, 42, ..., 15242]
+```
+
+## Compatibility
+
+| Linux | FreeBSD | NetBSD | SunOS | macOS | Win | AIX |
+| --- | --- | --- | --- | --- | --- | --- |
+| ✅ | ❓ | ❓ | ❓ | ✅ | ✅ | ❓ |
+
+✅ = Working
+❓ = Not tested but should work
+
+Please if your platform is not supported [file an issue][new issue].
+
+## CLI
+
+<img src="https://github.com/simonepri/pidtree/raw/master/media/cli.gif" alt="pidtree cli" width="300" align="right"/>
+Show a tree of the processes inside your system inside your terminal.
+
+```bash
+npx pidtree $PPID
+```
+Just replace `$PPID` with one of the pids inside your system.
+
+Or don't pass anything if you want all the pids inside your system.
+
+```bash
+npx pidtree
+```
+
+To display the output as a list, similar to the one produced from `pgrep -P $PID`,
+pass the `--list` flag.
+
+```bash
+npx pidtree --list
+```
+
+## API
+
+<a name="pidtree"></a>
+
+## pidtree(pid, [options], [callback]) ⇒ <code>[Promise.&lt;Array.&lt;Object&gt;&gt;]</code>
+Get the list of children pids of the given pid.
+
+**Kind**: global function
+**Returns**: <code>Promise.&lt;Array.&lt;Object&gt;&gt;</code> - Only when the callback is not provided.
+**Access**: public
+
+| Param | Type | Default | Description |
+| --- | --- | --- | --- |
+| pid | <code>Number</code> \| <code>String</code> | | A pid. If -1 will return all the pids. |
+| [options] | <code>Object</code> | | Optional options object. |
+| [options.root] | <code>Boolean</code> | <code>false</code> | Include the provided pid in the list. Ignored if -1 is passed as pid. |
+| [callback] | <code>function</code> | | Called when the list is ready. If not provided a promise is returned instead. |
+
+## Related
+
+- [pidusage][gh:pidusage] -
+Cross-platform process cpu % and memory usage of a PID
+
+## Authors
+
+- **Simone Primarosa** - [simonepri][github:simonepri]
+
+See also the list of [contributors][contributors] who participated in this project.
+
+## License
+
+This project is licensed under the MIT License - see the [license][license] file for details.
+
+<!-- Links -->
+[new issue]: https://github.com/simonepri/pidtree/issues/new
+[license]: https://github.com/simonepri/pidtree/tree/master/license
+[contributors]: https://github.com/simonepri/pidtree/contributors
+
+[github:simonepri]: https://github.com/simonepri
+
+[gh:pidusage]: https://github.com/soyuka/pidusage
+[gh:ps-tree]: https://github.com/indexzero/ps-tree
+[gh:ps-tree-um]: https://github.com/indexzero/ps-tree/issues/30