Skip to content
Open
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
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ module.exports = function (pid, signal, callback) {
function killAll (tree, signal, callback) {
var killed = {};
try {
Object.keys(tree).forEach(function (pid) {
Object.keys(tree).reverse().forEach(function (pid) {
tree[pid].forEach(function (pidpid) {
if (!killed[pidpid]) {
killPid(pidpid, signal);
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "tree-kill",
"version": "1.2.2",
"version": "1.2.3",
"description": "kill trees of processes",
"main": "index.js",
"types": "index.d.ts",
"bin": {
"tree-kill": "cli.js"
},
"scripts": {
"test": "mocha"
"test": "mocha test/test.js"
},
"repository": {
"type": "git",
Expand Down
6 changes: 6 additions & 0 deletions test/split_and_spin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
var fork = require('child_process').fork;
fork('./test/spin')
fork('./test/spin')
setInterval(function(){
// Do nothing
}, 100);
18 changes: 12 additions & 6 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var assert = require('assert');
var fork = require('child_process').fork;
var kill = require('..');
const { spawnSync } = require('child_process');

describe('kill()', function(){
it('should kill a process', function(done){
Expand Down Expand Up @@ -33,19 +34,13 @@ describe('kill()', function(){
})

it('should reject invalid pid', function(done){
var p = fork('./test/spin')
assert.ok(p.pid)

kill('rm -rf /dev/null', function(err) {
assert.ok(typeof err === 'object')
return done()
})
})

it('should reject invalid pids even if no callback', function(done){
var p = fork('./test/spin')
assert.ok(p.pid)

try {
kill('rm -rf /dev/null')
assert.fail('should have thrown')
Expand All @@ -54,4 +49,15 @@ describe('kill()', function(){
return done();
}
})

it('should self kill even if multiple sub-branches of processes', function(done){
var p = fork('./test/split_and_spin')
assert.ok(p.pid)

p.on('exit', function(code, signal){
assert.ok(code || signal, 'should return an exit code')
return done()
});
setTimeout(() => kill(p.pid), 100)
})
})