diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000..1084dcf --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,29 @@ +# Test against this version of Node.js +environment: + matrix: + - nodejs_version: "4" + - nodejs_version: "5" + - nodejs_version: "6" + +platform: + - x86 + - x64 + +# Install scripts. (runs after repo cloning) +install: + # Get the latest stable version of Node.js or io.js + - ps: Install-Product node $env:nodejs_version $env:platform + # install modules + - npm install + +# Post-install test scripts. +test_script: + # Output useful info for debugging. + - node --version + - npm --version + # run tests + - npm run coverage + +# Don't actually build. +build: off + diff --git a/package.json b/package.json index a53637f..239355c 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ }, "homepage": "https://github.com/dwyl/terminate", "dependencies": { - "ps-tree": "1.0.1" + "ps-tree": "^1.1.0" }, "devDependencies": { "chalk": "^1.1.1", diff --git a/terminate.js b/terminate.js index 1c86c36..58f4b04 100644 --- a/terminate.js +++ b/terminate.js @@ -1,4 +1,3 @@ -var cp = require('child_process'); var psTree = require('ps-tree'); // see: http://git.io/jBHZ /** @@ -17,13 +16,22 @@ module.exports = function terminate(pid, callback) { throw new Error("No pid supplied to Terminate!") } psTree(pid, function (err, children) { - cp.spawn('kill', ['-9'].concat(children.map(function (p) { return p.PID }))) - .on('exit', function() { - if(callback && typeof callback === 'function') { - callback(err, true); - } else { // do nothing - console.log(children.length + " Processes Terminated!"); - } - }); + children.forEach(function (child) { + try { + process.kill(parseInt(child.PID), 'SIGKILL'); + } catch (error) { + // ignore + } + }); + try { + process.kill(pid, 'SIGKILL'); + } catch (error) { + // ignore + } + if(callback && typeof callback === 'function') { + callback(err, true); + } else { // do nothing + console.log(children.length + " Processes Terminated!"); + } }); }; diff --git a/test/exec/child.js b/test/exec/child.js index 0f5b84d..42e21b8 100644 --- a/test/exec/child.js +++ b/test/exec/child.js @@ -1,3 +1,5 @@ // does nothing child process console.log("Child process.id: "+process.pid); console.log(" - - - - - - - - - - - - - - - - - - - - - - - "); +// keep process alive for one minute +setTimeout(function () {}, 60000); diff --git a/test/test.js b/test/test.js index 5f5c66d..3c02185 100644 --- a/test/test.js +++ b/test/test.js @@ -33,7 +33,7 @@ test(cyan('Spawn a Parent process which has a few Child Processes'), function (t t.equal(children.length, 0, green("✓ No more active child processes (we killed them)")); t.end(); }) - },200); // give psTree time to kill the processes + },1000); // give psTree time to kill the processes },10); // give the child process time to spawn },200); // give the child process time to spawn });