diff --git a/index.js b/index.js index b6f4eca..e973522 100755 --- a/index.js +++ b/index.js @@ -8,12 +8,8 @@ function childrenOfPid( pid, callback) { if('function' !== typeof callback) throw new Error('childrenOfPid(pid, callback) expects callback') - if('number' == typeof pid) { + if('number' == typeof pid) pid = pid.toString() - } - else { - pid = parseInt(pid, 10).toString(); // force string - } es.connect( spawn('ps', ['-A', '-o', 'ppid,pid,stat,comm']).stdout, @@ -31,7 +27,7 @@ function childrenOfPid( pid, callback) { } return cb(null, row) } - return cb(); + return cb() }), es.writeArray(function (err, ps) { var parents = [pid], children = [] diff --git a/package.json b/package.json index 7d160f1..51a3a1b 100644 --- a/package.json +++ b/package.json @@ -13,25 +13,20 @@ "test": "test" } , "scripts": { - "quick": "./node_modules/tape/bin/tape ./test/*.js" -, "test": "./node_modules/.bin/istanbul cover ./node_modules/tape/bin/tape ./test/*.js" -, "direct": "./node_modules/.bin/istanbul cover ./node_modules/tape/bin/tape ./test/direct.js" + "test": "./node_modules/.bin/istanbul cover ./node_modules/tape/bin/tape ./test/*.js" , "coverage": "./node_modules/.bin/istanbul cover ./node_modules/tape/bin/tape ./test/*.js && ./node_modules/.bin/istanbul check-coverage --statements 100 --functions 100 --lines 100 --branches 100" -, "jshint": "./node_modules/jshint/bin/jshint -c .jshintrc --exclude-path .gitignore ." , "codeclimate": "CODECLIMATE_REPO_TOKEN=84436b4f13c70ace9c62e7f04928bf23c234eb212c0232d39d7fb1535beb2da5 ./node_modules/codeclimate-test-reporter/bin/codeclimate.js < ./coverage/lcov.info" } , "devDependencies": { "chalk": "^1.0.0" , "codeclimate-test-reporter": "0.0.4" -, "ignored": "^2.0.2" , "istanbul": "^0.3.4" -, "jshint": "^2.5.10" -, "mkdirp": "^0.5.0" , "pre-commit": "0.0.9" , "tape": "^3.0.3" } , "pre-commit": [ "coverage" +, "codeclimate" ] , "engines": { "node": ">=0.10" diff --git a/readme.markdown b/readme.markdown index 088a211..6c55fb0 100644 --- a/readme.markdown +++ b/readme.markdown @@ -9,12 +9,12 @@ this a feature of UNIX. solution: use `ps-tree` to get all processes that a child_process may have started, so that they may all be terminated. ``` js - var cp = require('child_process'), - psTree = require('ps-tree') +var cp = require('child_process'), + psTree = require('ps-tree') - var child = cp.exec("node -e 'while (true);'",function () {...}) +var child = cp.exec("node -e 'while (true);'",function () {...}) - child.kill() //this will not actually kill the child it will kill the `sh` process. +child.kill() //this will not actually kill the child it will kill the `sh` process. ``` @@ -35,15 +35,14 @@ but since it is in `wait` mode killing it does not kill the children. used ps tree like this: ``` js +var cp = require('child_process'), + psTree = require('ps-tree') - var cp = require('child_process'), - psTree = require('ps-tree') +var child = cp.exec("node -e 'while (true);'",function () {...}) - var child = cp.exec("node -e 'while (true);'",function () {...}) - - psTree(child.pid, function (err, children) { - cp.spawn('kill', ['-9'].concat(children.map(function (p) {return p.PID}))) - }) +psTree(child.pid, function (err, children) { + cp.spawn('kill', ['-9'].concat(children.map(function (p) {return p.PID}))) +}) ``` @@ -51,7 +50,6 @@ If you prefer to run **psTree** from the command line, use: `node ./bin/ps-tree.js` -
[![Build Status](https://travis-ci.org/nelsonic/ps-tree.svg)](https://travis-ci.org/nelsonic/ps-tree) [![Code Climate](https://codeclimate.com/github/nelsonic/ps-tree/badges/gpa.svg)](https://codeclimate.com/github/nelsonic/ps-tree) [![Test Coverage](https://codeclimate.com/github/nelsonic/ps-tree/badges/coverage.svg)](https://codeclimate.com/github/nelsonic/ps-tree) diff --git a/test/exec/child.js b/test/exec/child.js index 8be694a..0f5b84d 100644 --- a/test/exec/child.js +++ b/test/exec/child.js @@ -1,9 +1,3 @@ -// a basic node http server -var port = Math.floor(Math.random() * 60000) + 1000; -// require('http').createServer(function (req, res) { -// res.writeHead(200, {"Content-Type": "text/html"}); -// res.end('Hai'); -// }).listen(port); -console.log("Visit: http://127.0.0.1:"+port); -console.log("process.id: "+process.pid); +// does nothing child process +console.log("Child process.id: "+process.pid); console.log(" - - - - - - - - - - - - - - - - - - - - - - - ");