ps
A Node.js module for looking up running processes. This module uses Table-Parser to parse the output.
Before using this module, you should take look at section Existing Bugs You Should Know at the bottom of this doc.
Install
$ npm install ps-node
How Does It Work
This module uses different tools to get process list:
- Linux / Mac: use
ps
command. Since the default result from shell command$ ps
will not contain "command arguments" in linux like "ubuntu", ps-node add argumentslx
as default. Which means, the default value for optionpsargs
islx
. - Win: use command
wmic process get ProcessId,CommandLine
through "cmd", more info about wmic is here. Anyway, there is also another tool name tasklist in windows, which can also list all the running processes, but lack of command arguments infomation. But compared to wmic, I think this tool should have a higher performance. You should take a look at the wrapper for this tool tasklist by @sindresorhs if you are interested.
Compatibility
- Should work great in most *nix system.
- Should work on Win10/7 more system versions need to be test.
Any compatibility issue is welcomed.
Usage
Lookup process with specified pid
:
var ps = ; // A simple pid lookupps;
Or use RegExp to filter command
and arguments
:
var ps = ; // A simple pid lookupps;
Also, you can use kill
to kill process by pid
:
var ps = ; // A simple pid lookupps;
Method kill
also supports a signal
option to be passed. It's only a wrapper of process.kill()
with checking of that killing is finished after the method is called.
var ps = ; // Pass signal SIGKILL for killing the process without allowing it to clean upps;
you can use object as the second parameter to pass more options:
ps;
Notice that the nodejs build-in process.kill()
does not accept number as the signal, you will have to use string format.
You can also pass arguments to lookup
with psargs
as arguments for ps
command(Note that psargs
is not available in windows):
var ps = ; // A simple pid lookupps;
Lastly, you can filter a list of items by their PPID by passing a PPID to filter on. You will need to pass in a psarg
that provides the PPID in the results (-l
or -j
for instance).
var ps = ; // A simple pid lookupps;
Existing Bugs You Should Know
I'm still working on these bugs at the moment, before using this module in any serious way, please take a look at them, and take your own risk.