Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions doc/api/cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,41 @@ added: v0.11.14
This function returns `true` if the worker's process has terminated (either
because of exiting or being signaled). Otherwise, it returns `false`.

```js
const cluster = require('cluster');
const http = require('http');
const numCPUs = require('os').cpus().length;

if (cluster.isMaster) {
console.log(`Master ${process.pid} is running`);

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

cluster.on('fork', (worker) => {
console.log('worker is dead:', worker.isDead());
Comment thread
BridgeAR marked this conversation as resolved.
Outdated
});

cluster.on('exit', (worker, code, signal) => {
console.log('worker is dead:', worker.isDead());
Comment thread
BridgeAR marked this conversation as resolved.
Outdated
});

} else {
// Workers can share any TCP connection
// In this case it is an HTTP server
http.createServer((req, res) => {
res.writeHead(200);
res.end(`Current process\n ${process.pid}`);
process.kill(process.pid);
}).listen(8000);

// Make http://localhost:8000 to ckeck isDead method.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: typo

Suggested change
// Make http://localhost:8000 to ckeck isDead method.
// Make http://localhost:8000 to check isDead method.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Make" means "Make a connection to" here?

Suggested change
// Make http://localhost:8000 to ckeck isDead method.
// Connect to http://localhost:8000 to check isDead().

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Trott and @trivikr typo is fixed. Let me know other comment 😉

}

Comment thread
BridgeAR marked this conversation as resolved.
Outdated
```

### worker.kill([signal='SIGTERM'])
<!-- YAML
added: v0.9.12
Expand Down