ps-tree vs ps-list vs ps-node
Process Management Libraries Comparison
1 Year
ps-treeps-listps-nodeSimilar Packages:
What's Process Management Libraries?

These libraries are designed to help developers manage and interact with system processes in Node.js applications. They provide functionalities for listing running processes, retrieving process information, and managing process trees. This can be particularly useful for monitoring system performance, debugging applications, and managing resources effectively. Each library has its own unique features and use cases, making them suitable for different scenarios in process management.

Package Weekly Downloads Trend
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
ps-tree2,642,171152-236 years agoMIT
ps-list1,427,126273495 kB4-MIT
ps-node96,872129-288 years agoMIT
Feature Comparison: ps-tree vs ps-list vs ps-node

Process Listing

  • ps-tree:

    ps-tree excels in providing a hierarchical view of processes. It allows you to see not only the list of processes but also their parent-child relationships, enabling you to understand how processes are related and how they interact with each other.

  • ps-list:

    ps-list provides a straightforward API to retrieve a list of all running processes on the system. It returns an array of process objects, each containing details such as PID, name, and memory usage. This makes it easy to monitor system activity and gather information about running applications.

  • ps-node:

    ps-node allows you to access process information, including the PID and other attributes, but does not provide a comprehensive list of all processes. Instead, it focuses on retrieving information for specific processes, making it useful for targeted queries rather than broad listings.

Performance

  • ps-tree:

    ps-tree may introduce some overhead due to its need to traverse the process tree to establish relationships. However, it provides valuable insights into process hierarchies, which can justify any performance trade-offs in scenarios where understanding process relationships is crucial.

  • ps-list:

    ps-list is optimized for performance, allowing quick access to process data without significant overhead. It is designed to be lightweight and efficient, making it suitable for applications that require frequent process checks without impacting performance.

  • ps-node:

    ps-node is also designed for performance but focuses more on retrieving specific process details rather than listing all processes. It is efficient for targeted queries but may not be as fast as ps-list for bulk process retrieval.

Ease of Use

  • ps-tree:

    ps-tree has a slightly more complex API due to its focus on process hierarchies. While it provides powerful features, developers may need to invest more time in understanding how to utilize its capabilities effectively.

  • ps-list:

    ps-list is very user-friendly, with a simple API that makes it easy to integrate into applications. Developers can quickly get up and running with minimal setup, making it ideal for those who need quick access to process data.

  • ps-node:

    ps-node offers a straightforward API, but it may require a bit more understanding of how to query specific processes effectively. While still user-friendly, it may not be as intuitive as ps-list for beginners.

Use Cases

  • ps-tree:

    ps-tree is perfect for applications that require detailed insights into process hierarchies, such as system monitoring tools or debugging applications. It allows developers to understand how processes are related, which can be critical for resource management.

  • ps-list:

    ps-list is best suited for applications that need to monitor system performance or gather information about running applications. It is ideal for tools that require a snapshot of current processes without needing detailed relationships.

  • ps-node:

    ps-node is suitable for applications that need to interact with specific processes, such as monitoring or controlling them. It is useful in scenarios where developers need to query and manipulate individual processes directly.

Compatibility

  • ps-tree:

    ps-tree is designed to work across different platforms, but its functionality may vary slightly depending on the operating system. Developers should test it in their target environments to ensure it meets their needs effectively.

  • ps-list:

    ps-list is compatible with various operating systems, including Windows, macOS, and Linux, making it a versatile choice for cross-platform applications. This broad compatibility ensures that developers can use it in diverse environments without issues.

  • ps-node:

    ps-node also supports multiple operating systems, but it may have limitations in certain environments. It is essential to check compatibility based on specific use cases and system configurations.

How to Choose: ps-tree vs ps-list vs ps-node
  • ps-tree:

    Select ps-tree if you need to work with process trees, allowing you to retrieve parent-child relationships between processes. This is beneficial for applications that require detailed insights into process hierarchies and management.

  • ps-list:

    Choose ps-list if you need a lightweight solution for quickly retrieving a list of running processes along with their details. It is straightforward to use and provides essential information without additional overhead.

  • ps-node:

    Opt for ps-node if you require a simple and efficient way to get process information in a Node.js environment. It is particularly useful for applications that need to interact with processes directly and offers a minimalistic API.

README for ps-tree

ps-tree

Build Status Code Climate Test Coverage npm Version Node.js Version Dependency Status

Sometimes you cannot kill child processes like you would expect, this a feature of UNIX.

in UNIX, a process may terminate by using the exit call, and it's parent process may wait for that event by using the wait system call. the wait system call returns the process identifier of a terminated child, so that the parent tell which of the possibly many children has terminated. If the parent terminates, however, all it's children have assigned as their new parent the init process. Thus, the children still have a parent to collect their status and execution statistics. (from "operating system concepts")

Solution: use ps-tree to get all processes that a child_process may have started, so that they may all be terminated.

var cp = require('child_process'),
    psTree = require('ps-tree');

var child = cp.exec("node -e 'while (true);'", function () {...});

// This will not actually kill the child it will kill the `sh` process.
child.kill();

wtf? it's because exec actually works like this:

function exec (cmd, cb) {
  spawn('sh', ['-c', cmd]);
  ...
}

sh starts parses the command string and starts processes, and waits for them to terminate, but exec returns a process object with the pid of the sh process. However, since it is in wait mode killing it does not kill the children.

Use ps-tree like this:

var cp = require('child_process'),
    psTree = require('ps-tree');

var child = cp.exec("node -e 'while (true);'", function () { /*...*/ });

psTree(child.pid, function (err, children) {
  cp.spawn('kill', ['-9'].concat(children.map(function (p) { return p.PID })));
});

If you prefer to run psTree from the command line, use: node ./bin/ps-tree.js

Cross Platform support

The ps-tree module behaves differently on *nix vs. Windows by spawning different programs and parsing their output. This is based on process.platform and not on checking to see if a ps compatible program exists on the system.

*nix

  1. " " need to be striped
$ ps -A -o comm,ppid,pid,stat
COMMAND          PPID   PID STAT
bbsd             2899 16958 Ss
watch <defunct>  1914 16964 Z
ps              20688 16965 R+

Windows

  1. wmic PROCESS WHERE ParentProcessId=4604 GET Name,ParentProcessId,ProcessId,Status)
  2. The order of head columns is fixed
> wmic PROCESS GET Name,ProcessId,ParentProcessId,Status
Name                          ParentProcessId  ProcessId   Status
System Idle Process           0                0
System                        0                4
smss.exe                      4                228

LICENSE: MIT