You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/api/cluster.md
+35Lines changed: 35 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -381,6 +381,41 @@ added: v0.11.14
381
381
This function returns `true` if the worker's process has terminated (either
382
382
because of exiting or being signaled). Otherwise, it returns `false`.
383
383
384
+
```js
385
+
constcluster=require('cluster');
386
+
consthttp=require('http');
387
+
constnumCPUs=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
+
console.log('worker is dead:', worker.isDead());
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.
0 commit comments