Illumos ptools
Use Solaris/Illumos proc(1) tools in Node.js
NOTE: read the manpage before using any of these tools to understand their risks!
Install
npm install ptools
Usage
var ptools = ;
Functions
ptools.pwdx([pid], callback(err, dir))
Get the current working directory of a given pid (defaults to self
)
ptools.ptree(callback(err, tree))
Get the full process tree on the system. The return object is a series
of nested objects with children
and proc
values, keyed off the pid
.
ptools.pcred([pid], callback(err, cred))
Get the credentials of a running process (uid, gid, etc)
ptools.pldd([pid], callback(err, libraries))
Get a list of loaded libraries of a running process
ptools.pwait(pid, callback(err))
Fire the callback when a given pid dies
ptools.ptime([pid], callback(err, time))
Grabs a ptime snapshot of a given pid (defaults to self)
ptools.prun(pid, callback(err))
Call prun
on a given pid. No arguments other than a possible exception are
given to the completion callback.
ptools.pstop(pid, callback(err))
Call pstop
on a given pid. No arguments other than a possible exception are
given to the completion callback.
ptools.pargs([pid], callback(err, obj))
This function will parse the output of pargs -ea
to get the full environment and
argument list returned as { argv: [], envp: {} }
.
Examples
ptools.pwdx
var pwdx = pwdx;;
yields
/home/dave/dev/node-ptools
ptools.ptree
var ptree = ptree;;
yields (snipped for brevity)
ptools.pcred
var pcred = pcred;;
yields
ptools.pldd
var pldd = pldd;;
yields
ptools.pwait
var pwait = pwait;;
This callback will fire when process 245
has exited. err will be set if
any stderr was produced.
ptools.ptime
var ptime = ptime;;
yields
ptools.prun
var prun = prun;;
This will call prun
on pid 578
, and callback when it is done with a
possible error.
ptools.pstop
var pstop = pstop;;
This will call pstop
on pid 578
, and callback when it is done with a
possible error.
ptools.pargs
var pargs = pargs;;
yields
Known Limitations
Some scripts are JS implementations of the ptools, and some just fork+exec their respective tool.
JS Implementation
- pwdx
forx+exec
- pargs
- pldd
- ptree
- pcred
- pwait
- ptime
Tests
npm test
License
MIT Licensed