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

    pidtree

Cross platform children list of a PID


Version published
Weekly downloads
9.2M
decreased by-0.19%
Maintainers
1
Install size
22.6 kB
Created
Weekly downloads
 

Package description

What is pidtree?

The pidtree npm package is a Node.js module that allows you to list all running processes in a hierarchical tree structure based on their process IDs (PIDs). It can be used to find parent and child processes of a given PID, which is useful for monitoring and managing system processes programmatically.

What are pidtree's main functionalities?

Get an array of all running processes as a tree

This code sample demonstrates how to retrieve a tree of all running processes. The '-1' argument specifies that the tree should start with the root process. The callback function receives the tree structure or an error.

const pidtree = require('pidtree');
pidtree(-1, function (err, tree) {
  if (err) throw err;
  console.log(tree);
});

Get a tree of child processes for a specific PID

This code sample shows how to get a tree of child processes for a specific PID. Replace '1234' with the PID of the process you want to inspect. The callback function will receive the tree of child processes or an error.

const pidtree = require('pidtree');
const pid = 1234; // Replace with the target PID
pidtree(pid, function (err, tree) {
  if (err) throw err;
  console.log(tree);
});

Other packages similar to pidtree

Readme

Source

pidtree

Latest version on npm Downloads on npm Project license
Lint status Test macOS status Test Ubuntu status Test Windows status Codecov Coverage report Known Vulnerabilities
XO Code Style used AVA Test Runner used Istanbul Test Coverage used NI Scaffolding System used NP Release System used

🚸 Cross platform children list of a PID.
Coded with ❤️ by Simone Primarosa.

Synopsis

This package is really similar to ps-tree but is faster, safer and provides sub-children results.
Furthermore ps-tree is unmaintained.

Uuh, and a fancy CLI is also available!

Usage

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

LinuxFreeBSDNetBSDSunOSmacOSWinAIX

✅ = Working ❓ = Not tested but should work

Please if your platform is not supported file an issue.

CLI

pidtree cli Show a tree of the processes inside your system inside your terminal.
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.

npx pidtree

To display the output as a list, similar to the one produced from pgrep -P $PID, pass the --list flag.

npx pidtree --list

API

pidtree(pid, [options], [callback]) ⇒ [Promise.<Array.<Object>>]

Get the list of children pids of the given pid.

Kind: global function
Returns: Promise.<Array.<Object>> - Only when the callback is not provided.
Access: public

ParamTypeDefaultDescription
pidNumber | StringA pid. If -1 will return all the pids.
[options]ObjectOptional options object.
[options.root]BooleanfalseInclude the provided pid in the list. Ignored if -1 is passed as pid.
[callback]functionCalled when the list is ready. If not provided a promise is returned instead.
  • pidusage - Cross-platform process cpu % and memory usage of a PID

Authors

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the license file for details.

Keywords

FAQs

Last updated on 05 Jun 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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