ps-list vs ps-node vs ps-tree
Process Management in Node.js
ps-listps-nodeps-treeSimilar Packages:

Process Management in Node.js

Process management libraries in Node.js provide tools for interacting with and managing system processes. These libraries allow developers to list, monitor, and control processes running on a machine, which can be useful for tasks such as resource management, debugging, and building system utilities. ps-list is a lightweight library for listing running processes with minimal overhead, while ps-node offers a more feature-rich API for managing processes, including the ability to kill processes by name or PID. ps-tree focuses on retrieving the process tree, allowing developers to see parent-child relationships between processes, which is useful for managing process hierarchies and ensuring that all child processes are handled appropriately.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
ps-list0283504 kB45 months agoMIT
ps-node0129-289 years agoMIT
ps-tree0158-217 years agoMIT

Feature Comparison: ps-list vs ps-node vs ps-tree

Process Listing

  • ps-list:

    ps-list provides a simple and efficient way to list all running processes on a system. It returns an array of process objects with information such as PID, name, CPU, and memory usage. The library is lightweight and has minimal dependencies, making it fast and reliable for retrieving process information.

  • ps-node:

    ps-node also allows listing processes, but it is more focused on providing additional functionality for managing processes. It can list processes by name or PID and provides methods for killing processes. The library is more feature-rich but may have a slightly larger footprint compared to ps-list.

  • ps-tree:

    ps-tree does not provide a standalone process listing feature but focuses on retrieving the process tree for a given PID. It returns the parent-child relationships between processes, which can be useful for understanding the hierarchy and managing related processes.

Process Management

  • ps-list:

    ps-list is primarily designed for listing processes and does not provide built-in functionality for managing or controlling processes. It is best used for monitoring and retrieving process information.

  • ps-node:

    ps-node provides more comprehensive process management features, including the ability to kill processes by name or PID. It is designed for applications that need to interact with and control processes programmatically.

  • ps-tree:

    ps-tree focuses on managing process hierarchies by providing tools to retrieve and manipulate the process tree. It is particularly useful for ensuring that all child processes are handled appropriately when managing parent processes.

Process Tree

  • ps-list:

    ps-list does not provide functionality for retrieving process trees or parent-child relationships. It focuses on providing a flat list of all running processes.

  • ps-node:

    ps-node does not have built-in support for process trees but allows for basic process management and control. It can be used in conjunction with other libraries to manage process hierarchies.

  • ps-tree:

    ps-tree specializes in retrieving the process tree for a given PID, providing detailed information about parent and child processes. This is useful for applications that need to manage process hierarchies and ensure that all related processes are handled correctly.

Cross-Platform Support

  • ps-list:

    ps-list is designed to work across multiple platforms, including Windows, macOS, and Linux. It uses platform-specific commands to retrieve process information, ensuring compatibility across different operating systems.

  • ps-node:

    ps-node also supports cross-platform process management, allowing developers to interact with processes on Windows, macOS, and Linux. It provides a consistent API for managing processes across different platforms.

  • ps-tree:

    ps-tree is cross-platform and works on Windows, macOS, and Linux. It uses platform-specific methods to retrieve the process tree, ensuring that it can provide accurate parent-child process information regardless of the operating system.

Ease of Use: Code Examples

  • ps-list:

    Listing processes with ps-list

    const psList = require('ps-list');
    
    (async () => {
      const processes = await psList();
      console.log(processes);
    })();
    
  • ps-node:

    Managing processes with ps-node

    const ps = require('ps-node');
    
    // List all processes
    ps.lookup({}, (err, resultList) => {
      if (err) throw err;
      console.log(resultList);
    });
    
    // Kill a process by PID
    ps.kill(12345, (err) => {
      if (err) {
        console.log('Failed to kill process:', err);
      } else {
        console.log('Process killed successfully');
      }
    });
    
  • ps-tree:

    Retrieving process tree with ps-tree

    const psTree = require('ps-tree');
    const pid = 12345; // Parent process ID
    
    psTree(pid, (err, children) => {
      if (err) throw err;
      console.log('Child processes:', children);
    });
    

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

  • ps-list:

    Choose ps-list if you need a simple and efficient way to list all running processes on a system. It is ideal for applications that require process information without the need for extensive management features.

  • ps-node:

    Choose ps-node if you need a more comprehensive solution for managing processes, including the ability to kill processes by name or PID. It is suitable for applications that require more control over processes and need to perform actions on them.

  • ps-tree:

    Choose ps-tree if you need to understand the hierarchy of processes, especially when dealing with parent-child relationships. It is useful for applications that need to manage process trees, such as ensuring that all child processes are terminated when a parent process is killed.

README for ps-list

ps-list

Get running processes

Works on macOS, Linux, and Windows. Windows ARM64 is not supported yet.

Install

npm install ps-list

Usage

import psList from 'ps-list';

console.log(await psList());
//=> [{pid: 3213, name: 'node', cmd: 'node test.js', ppid: 1, uid: 501, cpu: 0.1, memory: 1.5, path: '/usr/local/bin/node', startTime: 2025-01-15T10:30:00.000Z}, …]

API

psList(options?)

Returns a Promise<ProcessDescriptor[]> with the running processes.

On macOS and Linux:

  • The name property is truncated to 15 characters by the system
  • The cmd property contains the full command line with arguments
  • The cpu property is the CPU usage percentage (0-100)
  • The memory property is the memory usage percentage (0-100)
  • The path property is a best-effort attempt to get the full executable path:
    • On Linux: reads from /proc/{pid}/exe when available
    • On macOS: extracted from command line when possible
    • Falls back to comm (which may be truncated)
  • The startTime property contains the process start time as a Date object

The cmd, cpu, memory, uid, path, and startTime properties are not available on Windows.

options

Type: object

all

Type: boolean
Default: true

Include other users' processes as well as your own.

On Windows this has no effect and will always be the user's own processes.

Related

  • fastlist - The binary used in this module to list the running processes on Windows