node-tree-kill icon indicating copy to clipboard operation
node-tree-kill copied to clipboard

Does not kill child process on MacOS

Open barnabasbartha opened this issue 6 years ago • 3 comments

In some cases I want to kill a child process spawned from node, but even if I use this package giving the process's PID number, the process lives happily and does not close. Any idea?

barnabasbartha avatar Sep 11 '19 09:09 barnabasbartha

Does the callback function gets executed?

var kill = require('tree-kill');
kill(1, 'SIGKILL', function(err) {
    // Do things
});

samuelpetroline avatar Oct 17 '19 04:10 samuelpetroline

Same problem in mac. The default SIGTERM cause self pid can not be killed. SIGKILL will kill self pid.

This is also work:

kill(1, function(err) {
    // Do things
    setTimeout(() => {
      process.kill(1)
    }, 200)
});

yantze avatar Sep 10 '20 11:09 yantze

Same issue here. I've found out that the solution by ps-tree works:

psTree(child.pid, function (err, children) {
  cp.spawn('kill', ['-9'].concat(children.map(function (p) { return p.PID })));
});

I do wonder if there's much point for this package to replicate the logic already in ps-tree? Just have ps-tree as a dependency and use in buildProcessTree?

Izhaki avatar Apr 26 '21 10:04 Izhaki