pkrumins / node-tree-kill

kill trees of processes
MIT License
333 stars 37 forks source link

Does not kill child process on MacOS #28

Open barnabasbartha opened 4 years ago

barnabasbartha commented 4 years ago

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?

samuelpetroline commented 4 years ago

Does the callback function gets executed?

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

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)
});
Izhaki commented 3 years ago

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?