Skip to content

Instantly share code, notes, and snippets.

@BorePlusPlus
Last active December 20, 2015 23:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save BorePlusPlus/6212241 to your computer and use it in GitHub Desktop.
Save BorePlusPlus/6212241 to your computer and use it in GitHub Desktop.
node.js cluster kill
var cluster = require('cluster');
if (cluster.isMaster) {
cluster.fork();
cluster.on('exit', function(worker, code, signal) {
console.log('Worker exited:', worker.process.pid);
});
setTimeout(function () {
for (var id in cluster.workers) {
var worker = cluster.workers[id];
worker.kill('SIGUSR2');
}
}, 2000);
} else {
process.on('SIGUSR2', function() {
//WHY DOES THIS NOT GET CALLED? http://nodejs.org/api/cluster.html#cluster_worker_kill_signal_sigterm
console.log('SIGUSR2 called', process.pid);
});
console.log('Worker listening for SIGUSR2', process.pid);
}
@inexplicable
Copy link

it's very interesting that

worker.kill('SIGUSR1');
worker.process.kill('SIGUSR1');

did completely different things for me as i was probably trying the same thing above.
and the 2nd would actually work as expected:

worker:11380 listening!
Hit SIGUSR1 - starting debugger agent.
debugger listening on port 5858

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment