Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds Tests and Updates Dependency #12

Merged
merged 4 commits into from
Apr 11, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 = []
Expand Down
9 changes: 2 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
22 changes: 10 additions & 12 deletions readme.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.

```

Expand All @@ -35,23 +35,21 @@ 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})))
})

```

If you prefer to run **psTree** from the command line,
use: `node ./bin/ps-tree.js`


<br /> <!-- badges -->
[![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)
Expand Down
10 changes: 2 additions & 8 deletions test/exec/child.js
Original file line number Diff line number Diff line change
@@ -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(" - - - - - - - - - - - - - - - - - - - - - - - ");