joyent/node — Issue #2060: node clusters cannot be killed
Author: christophsturm
Created: 2011-11-09 15:01:42+00:00
State: open

with the demo code from the cluster docs:

var cluster = require('cluster');
var http = require('http');
var numCPUs = require('os').cpus().length;

if (cluster.isMaster) {
// Fork workers.
for (var i = 0; i < numCPUs; i++) {
cluster.fork();
}

cluster.on('death', function(worker) {
console.log('worker ' + worker.pid + ' died');
});
} else {
// Worker processes have a http server.
http.Server(function(req, res) {
res.writeHead(200);
res.end("hello world\n");
}).listen(8000);
}

chi:petrol christoph$ node minicluster.js &
[1] 14330
chi:petrol christoph$ Worker 14332 online
Worker 14333 online
Worker 14331 online
Worker 14334 online

chi:petrol christoph$ kill 14330
$ ps | grep node
14331 ttys000 0:00.10 /Users/christoph/.nvm/v0.6.0/bin/node /Users/christoph/Projects/collmedia/petrol/minicluster.js
14332 ttys000 0:00.10 /Users/christoph/.nvm/v0.6.0/bin/node /Users/christoph/Projects/collmedia/petrol/minicluster.js
14333 ttys000 0:00.10 /Users/christoph/.nvm/v0.6.0/bin/node /Users/christoph/Projects/collmedia/petrol/minicluster.js
14334 ttys000 0:00.10 /Users/christoph/.nvm/v0.6.0/bin/node /Users/christoph/Projects/collmedia/petrol/minicluster.js
$ curl http://127.0.0.1:8000/
hello world
$ node -v
v0.6.0