Skip to content
This repository was archived by the owner on Apr 22, 2023. It is now read-only.
This repository was archived by the owner on Apr 22, 2023. It is now read-only.

How to end cluster's worker process gracefully? #2088

@avz

Description

@avz

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

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]#

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions