We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 69f17f1 commit b6d0cbcCopy full SHA for b6d0cbc
1 file changed
doc/api/cluster.md
@@ -381,6 +381,41 @@ added: v0.11.14
381
This function returns `true` if the worker's process has terminated (either
382
because of exiting or being signaled). Otherwise, it returns `false`.
383
384
+```js
385
+const cluster = require('cluster');
386
+const http = require('http');
387
+const numCPUs = require('os').cpus().length;
388
+
389
+if (cluster.isMaster) {
390
+ console.log(`Master ${process.pid} is running`);
391
392
+ // Fork workers.
393
+ for (let i = 0; i < numCPUs; i++) {
394
+ cluster.fork();
395
+ }
396
397
+ cluster.on('fork', (worker) => {
398
+ console.log('worker is dead:', worker.isDead());
399
+ });
400
401
+ cluster.on('exit', (worker, code, signal) => {
402
403
404
405
+} else {
406
+ // Workers can share any TCP connection
407
+ // In this case it is an HTTP server
408
+ http.createServer((req, res) => {
409
+ res.writeHead(200);
410
+ res.end(`Current process\n ${process.pid}`);
411
+ process.kill(process.pid);
412
+ }).listen(8000);
413
414
+ // Make http://localhost:8000 to ckeck isDead method.
415
+}
416
417
+```
418
419
### worker.kill([signal='SIGTERM'])
420
<!-- YAML
421
added: v0.9.12
0 commit comments