Skip to content

Commit

Permalink
kill all children of a monitored process.
Browse files Browse the repository at this point in the history
  • Loading branch information
dominictarr authored and indexzero committed Oct 9, 2011
1 parent 89be252 commit a83a1e1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/forever/monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var util = require('util'),
winston = require('winston'),
watch = require('watch'),
minimatch = require('minimatch'),
psTree = require('ps-tree'),
forever = require('../forever');

//
Expand Down Expand Up @@ -372,9 +373,14 @@ Monitor.prototype.kill = function (forceStop) {
if (forceStop) {
this.forceStop = true;
}
psTree(this.child.pid, function (err, children) {
var pids = children.map(function (p) { return p.PID })
pids.shift(self.child.pid)
spawn('kill', ['-9'].concat(pids)).on('exit', function () {
self.emit('stop', self.childData);
})
})

this.child.kill();
this.emit('stop', this.childData);
}

return this;
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"timespan": "2.0.x",
"watch": "0.3.x",
"minimatch": "0.0.x",
"ps-tree": "0.0.x",
"winston": "0.5.x"
},
"devDependencies": {
Expand Down

0 comments on commit a83a1e1

Please sign in to comment.