Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

42 lines (33 sloc) 0.908 kb

ps

A Node.js module for looking up running processes.

Install

$ npm install ps

Usage

var ps = require('ps');

// A simple pid lookup
ps.lookup({ pid: 12345 }, function(err, proc) {
    if (err) {throw err;}
    if (proc) {
        console.log(proc);  // Process name, something like "node" or "bash"
    } else {
        console.log('No such process');
    }
});

// Lookup processes in a list of pids and format them
var query = {
    pid: [123, 234, 345],  // Look up these pids
    format: 'pid comm',    // Retrieve the pid and name, like running `ps -o pid= -o comm=`
    parse: true            // Parse the output results into a 2D array
};
ps.lookup(query, function(err, results) {
    if (err) {throw err;}
    if (results) {
        results.forEach(function(proc) {
            console.log('PID: ' + proc[0] + '; Name: ' + proc[1]);
        });
    }
});
Jump to Line
Something went wrong with that request. Please try again.