Socket
Socket
Sign inDemoInstall

pidtree

Package Overview
Dependencies
0
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.3 to 0.1.4

35

index.js
'use strict';
module.exports = require('./lib/tree');
function pify(fn, arg1, arg2) {
return new Promise(function(resolve, reject) {
fn(arg1, arg2, function(err, data) {
if (err) return reject(err);
resolve(data);
});
});
}
var tree = require('./lib/tree');
/**
* Get the list of child pids of the given pid.
* @public
* @param {Number|String} pid A pid.
* @param {Object} [options] Optional options object.
* @param {Boolean} [options.root=false] Include the provided pid in the list.
* @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 pidtree(pid, options, callback) {
if (typeof options === 'function') {
callback = options;
options = undefined;
}
if (typeof callback === 'function') {
tree(pid, options, callback);
return;
}
return pify(tree, pid, options);
}
module.exports = pidtree;

6

lib/ps.js

@@ -40,6 +40,3 @@ 'use strict';

for (var i = 1; i < stdout.length; i++) {
var line = stdout[i]
.trim()
.replace(/\s\s+/g, ' ')
.split(' ');
var line = stdout[i].trim().split(/\s+/);

@@ -79,2 +76,3 @@ if (!line || line.length !== 2) {

}
delete tree[cur];
}

@@ -81,0 +79,0 @@ pids.shift(); // Remove root

@@ -29,3 +29,2 @@ 'use strict';

* Get the list of child pids of the given pid
* @public
* @param {Number|String} pid A pid.

@@ -41,2 +40,6 @@ * @param {Object} [options] Optional options object.

}
if (typeof options !== 'object') {
options = {};
}
if (file === undefined) {

@@ -43,0 +46,0 @@ return callback(

@@ -31,6 +31,3 @@ 'use strict';

for (var i = 1; i < stdout.length; i++) {
var line = stdout[i]
.trim()
.replace(/\s\s+/g, ' ')
.split(' ');
var line = stdout[i].trim().split(/\s+/);

@@ -70,2 +67,3 @@ if (!line || line.length !== 2) {

}
delete tree[cur];
}

@@ -72,0 +70,0 @@ pids.shift(); // Remove root

{
"name": "pidtree",
"version": "0.1.3",
"version": "0.1.4",
"description": "Cross platform children list of a PID",

@@ -22,3 +22,9 @@ "license": "MIT",

"pid",
"pidtree"
"pidtree",
"pgrep",
"list",
"all",
"system",
"process",
"processes"
],

@@ -25,0 +31,0 @@ "main": "index.js",

@@ -80,4 +80,4 @@ <h1 align="center">

// Get childs of current process
pidtree(process.pid, function (err, stat) {
console.log(stat)
pidtree(process.pid, function (err, pids) {
console.log(pids)
// => []

@@ -87,4 +87,4 @@ })

// Include the given pid in the result array
pidtree(process.pid, {root: true}, function (err, stat) {
console.log(stat)
pidtree(process.pid, {root: true}, function (err, pids) {
console.log(pids)
// => [727]

@@ -94,6 +94,11 @@ })

// Get all the processes of the System on *nix
pidtree(1, function (err, stat) {
console.log(stat)
pidtree(1, function (err, pids) {
console.log(pids)
// => [41,45,43,530,47,50, ..., 41241, 32]
})
// If no callback is given it returns a promise instead
const pids = await pidtree(1)
console.log(pids)
// => [41,45,43,530,47,50, ..., 41241, 32]
```

@@ -114,3 +119,3 @@

This package behave similar to `pgrep` on \*unix
This package behave similarly to `pgrep -P` on \*unix

@@ -132,25 +137,17 @@ ```bash

### pidtree(pids, callback)
Get pid informations.
## pidtree(pid, [options], [callback]) ⇒ <code>Promise.&lt;Object&gt;</code>
Get the list of child pids of the given pid.
**Kind**: global function
**Returns**: <code>Promise.&lt;Object&gt;</code> - Only when the callback is not provided.
**Access**: public
| Param | Type | Default |Description |
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| pids | <code>Number</code> \| <code>String</code> | | A pid. |
| options | <code>Object</code> | | Optional options object. |
| options.root | <code>Boolean</code> | false | Include the provided pid in the list. |
| callback | [<code>pidCallback</code>](#pidCallback) | | Called when the list is ready. |
| pid | <code>Number</code> \| <code>String</code> | | A pid. |
| [options] | <code>Object</code> | | Optional options object. |
| [options.root] | <code>Boolean</code> | <code>false</code> | Include the provided pid in the list. |
| [callback] | <code>function</code> | | Called when the list is ready. If not provided a promise is returned instead. |
<a name="pidCallback"></a>
### pidCallback : <code>function</code>
**Kind**: global typedef
| Param | Type | Description |
| --- | --- | --- |
| err | <code>Error</code> | A possible error. |
| statistics | <code>Array.&lt;Number&gt;</code> | The array containing the child pids. |
## Related

@@ -157,0 +154,0 @@ - [pidusage][gh:pidusage] -

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc