joyent/node — Issue #2088: How to end cluster's worker process gracefully?
Author: avz
Created: 2011-11-13 12:45:16+00:00
State: open

How i can cause exit of worker process (end worker's event loop) without calling ```process.exit()```?

```javascript
var cluster = require('cluster');

if(cluster.isMaster) {
process.stdout.write('Starting worker ... ')

cluster.fork();

cluster.on('death', function(worker) {
console.log('worker ' + worker.pid + ' died');
});
} else {
process.stdout.write('done\n')
process.stdout.write('Now worker must gracefully die\n')
}
```

Result

```
arepo@home [/tmp]# node a.js
Starting worker ... done
Now worker must gracefully die
<...nothing happens...>
^Czsh: exit 1 node a.js
```

Expected result:

```
arepo@home [/tmp]# node a.js
Starting worker ... done
Now worker must gracefully die
worker 9992 died
arepo@home [/tmp]#
```