-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
doc: add example function isDead to cluster #28362
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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()); | ||||||||||
| }); | ||||||||||
|
|
||||||||||
| cluster.on('exit', (worker, code, signal) => { | ||||||||||
| console.log('worker is dead:', worker.isDead()); | ||||||||||
|
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. | ||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: typo
Suggested change
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "Make" means "Make a connection to" here?
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||
| } | ||||||||||
|
|
||||||||||
|
BridgeAR marked this conversation as resolved.
Outdated
|
||||||||||
| ``` | ||||||||||
|
|
||||||||||
| ### worker.kill([signal='SIGTERM']) | ||||||||||
| <!-- YAML | ||||||||||
| added: v0.9.12 | ||||||||||
|
|
||||||||||
Uh oh!
There was an error while loading. Please reload this page.