Skip to content

Native Node.js binding for enumerate, find and kill processes by OS specific API

License

Notifications You must be signed in to change notification settings

kuzalekon/node-ps-native

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ps-native

Native Node.js binding for enumerate, find and kill processes by OS specific API

Installation

Note: The module is uses the node-gyp and c++ compiler with c++11 support to build the extension.

You can use npm to download and install it:

  • The latest ps-native package: npm install ps-native
  • GitHub's master branch: npm install https://github.com/kalexey89/node-ps-native/tarball/master

Supported OS and platforms

OS:

  • Windows (desktop: Window 7+, server: Windows Server 2008+);
  • Linux (any Linux-based distributives);
  • MacOS (plans...).

Platforms:

  • Node.js (version >= 4);
  • NW.js (if NW.js contains a supported version of Node.js).

Usage

Note: the module must be installed before use.

const ps = require('ps-native');

/*
 * Enumerate processes
 */

ps.enum(['pid', 'name'], (error, proclist) => {
    if (null === error) console.log(proclist);
    else throw error;
});


/*
 * Find processes
 */

// By PID
ps.find(4354, ['pid', 'name'], (error, proc) => {
    if (null === error) console.log(proc);
    else throw error;
});

// By name
ps.find('gedit', ['pid', 'name'], (error, proclist) => {
    if (null === error) console.log(proclist);
    else throw error;
});

// By regexp
ps.find(/ch.*/, ['pid', 'name'], (error, proclist) => {
    if (null === error) console.log(proclist);
    else throw error;
});


/*
 * Kill process
 */
 
ps.kill(4532, ps.SIGTERM, (error) => {
    if (null !== error) throw error;
});

API

See the API documentation in the wiki.

Testing

mocha is required to run unit tests.

In ps-native directory (where its package.json resides) run the following:

npm install mocha
npm test

License

MIT, © 2017 Kuznetsov Aleksey (kalexey89).