Native Node.js binding for enumerate, find and kill processes by OS specific API
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
OS:
Windows
(desktop: Window 7+, server: Windows Server 2008+);Linux
(any Linux-based distributives);MacOS(plans...).
Platforms:
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;
});
See the API documentation in the wiki.
mocha
is required to run unit tests.
In ps-native
directory (where its package.json
resides) run the following:
npm install mocha
npm test
MIT
, © 2017 Kuznetsov Aleksey (kalexey89).