{"name":"ps-node","version":"0.1.5","description":"A process lookup utility","main":"index.js","repository":{"type":"git","url":"git://github.com/neekey/ps.git"},"scripts":{"test":"node ./node_modules/mocha/bin/mocha -t 0 -R spec test/test.js","testWatch":"node ./node_modules/mocha/bin/mocha -t 0 -R spec --watch test/test.js"},"keywords":["ps","process","lookup","pid"],"dependencies":{"table-parser":"^0.1.3"},"license":"MIT","devDependencies":{"mocha":"^2.4.5"},"gitHead":"720798dc1d59be6dd2558da5b41229ada5de8c42","bugs":{"url":"https://github.com/neekey/ps/issues"},"homepage":"https://github.com/neekey/ps#readme","_id":"ps-node@0.1.5","_shasum":"b51e5dd5650fe12ab4785d76ac4770dfbc56f986","_from":".","_npmVersion":"3.8.6","_nodeVersion":"5.12.0","_npmUser":{"name":"neekey","email":"ni184775761@gmail.com"},"dist":{"shasum":"b51e5dd5650fe12ab4785d76ac4770dfbc56f986","tarball":"http://registry-npm.ywwl.com/ps-node/download/ps-node-0.1.5.tgz","integrity":"sha512-J2krEAU3CAGdptw9U3IU1QXTxjTdy49YkABSdwlpcXBNAkxBTWB8TuBE+jHh4YPfCXDkIBcpnkJevo4b2Yt2zA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDKNJGUvJLBgpPn+dlQQz0Sz6Fe08dVTEZ8ubnv4CNqLAIgLwmWdxcvV6OEm03bQsonOZAO138mDmj4eOuro+SqvAg="}],"size":7042,"noattachment":false,"key":"/ps-node/-/ps-node-0.1.5.tgz"},"maintainers":[{"name":"neekey","email":"ni184775761@gmail.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/ps-node-0.1.5.tgz_1490496223554_0.7572478034999222"},"directories":{},"readme":"# ps [![Build Status](https://travis-ci.org/neekey/ps.svg?branch=master)](https://travis-ci.org/neekey/ps) [![Build status](https://ci.appveyor.com/api/projects/status/fhom8ot12b6jxeyt?svg=true)](https://ci.appveyor.com/project/neekey/ps)\n\nA Node.js module for looking up running processes. This module uses [Table-Parser](https://github.com/neekey/table-parser) to parse the output.\n\nBefore using this module, you should take look at section [Existing Bugs You Should Know](https://github.com/neekey/ps#user-content-existing-bugs-you-should-know) at the bottom of this doc.\n\n## Install\n\n```bash\n$ npm install ps-node\n```\n\n## How Does It Work\n\nThis module uses different tools to get process list:\n\n- 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 arguments `lx` as default. Which means, the default value for option `psargs` is `lx`.\n- Win: use command `wmic process get ProcessId,CommandLine` through \"cmd\", more info about wmic is [here](https://social.technet.microsoft.com/Forums/windowsserver/en-US/ab6c7e6e-4ad4-4237-bab3-0349cd76c094/wmic-command-line-utilities?forum=winservercore). Anyway, there is also another tool name [tasklist](https://technet.microsoft.com/en-us/library/bb491010.aspx) 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](https://github.com/sindresorhus/tasklist) by @sindresorhs if you are interested.\n\n## Compatibility\n\n- Should work great in most *nix system.\n- Should work on Win10/7 more system versions need to be test.  \n\nAny compatibility issue is welcomed.\n\n## Usage\n\nLookup process with specified `pid`:\n\n```javascript\nvar ps = require('ps-node');\n\n// A simple pid lookup\nps.lookup({ pid: 12345 }, function(err, resultList ) {\n    if (err) {\n        throw new Error( err );\n    }\n\n    var process = resultList[ 0 ];\n\n    if( process ){\n\n        console.log( 'PID: %s, COMMAND: %s, ARGUMENTS: %s', process.pid, process.command, process.arguments );\n    }\n    else {\n        console.log( 'No such process found!' );\n    }\n});\n\n```\n\nOr use RegExp to filter `command` and `arguments`:\n\n```javascript\nvar ps = require('ps-node');\n\n// A simple pid lookup\nps.lookup({\n    command: 'node',\n    arguments: '--debug',\n    }, function(err, resultList ) {\n    if (err) {\n        throw new Error( err );\n    }\n\n    resultList.forEach(function( process ){\n        if( process ){\n\n            console.log( 'PID: %s, COMMAND: %s, ARGUMENTS: %s', process.pid, process.command, process.arguments );\n        }\n    });\n});\n\n```\n\nAlso, you can use `kill` to kill process by `pid`:\n\n```javascript\nvar ps = require('ps-node');\n\n// A simple pid lookup\nps.kill( '12345', function( err ) {\n    if (err) {\n        throw new Error( err );\n    }\n    else {\n        console.log( 'Process %s has been killed!', pid );\n    }\n});\n```\n\nMethod `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.\n\n```javascript\nvar ps = require('ps-node');\n\n// Pass signal SIGKILL for killing the process without allowing it to clean up\nps.kill( '12345', 'SIGKILL', function( err ) {\n    if (err) {\n        throw new Error( err );\n    }\n    else {\n        console.log( 'Process %s has been killed without a clean-up!', pid );\n    }\n});\n```\n\nyou can use object as the second parameter to pass more options:\n\n```js\nps.kill( '12345', { \n    signal: 'SIGKILL',\n    timeout: 10,  // will set up a ten seconds timeout if the killing is not successful\n}, function(){});\n\n```\n\nNotice that the nodejs build-in `process.kill()` does not accept number as the signal, you will have to use string format.\n\n\nYou can also pass arguments to `lookup` with `psargs` as arguments for `ps` command（Note that `psargs` is not available in windows):\n\n```javascript\nvar ps = require('ps-node');\n\n// A simple pid lookup\nps.lookup({\n    command: 'node',\n    psargs: 'ux'\n    }, function(err, resultList ) {\n    if (err) {\n        throw new Error( err );\n    }\n\n    resultList.forEach(function( process ){\n        if( process ){\n            console.log( 'PID: %s, COMMAND: %s, ARGUMENTS: %s', process.pid, process.command, process.arguments );\n        }\n    });\n});\n\n```\n\nLastly, 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).\n\n```javascript\nvar ps = require('ps-node');\n\n// A simple pid lookup\nps.lookup({\n    command: 'mongod',\n    psargs: '-l',\n    ppid: 82292\n    }, function(err, resultList ) {\n    if (err) {\n        throw new Error( err );\n    }\n\n    resultList.forEach(function( process ){\n        if( process ){\n            console.log( 'PID: %s, COMMAND: %s, ARGUMENTS: %s', process.pid, process.command, process.arguments );\n        }\n    });\n});\n\n```\n\n## Existing Bugs You Should Know\n\nI'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.\n\n- [multiple-bytes characters may cause parse error](https://github.com/neekey/table-parser/issues/4).\n","publish_time":1490496225686,"_cnpm_publish_time":1490496225686,"dist-tags":{"latest":"0.1.6"}}