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
consthttp=require('http');constprocess=require('process');constPORT=3001;constserver=http.createServer((req,res)=>{res.write('hello fork');res.end();});server.listen(PORT,()=>{console.log(`the server is start at port ${PORT}, PID=${process.pid}`)})
主要功能
多进程启动和自动守护代码
./fork.js
多进程守护使用
index.js
worker.js
测试效果
启动多进程守护
手动删除其中的一个子进程
可以看出当监听到子进程退出后,就会自动重启一个新的进程,保证指定数量多进程的执行
参考代码
https://github.com/node-modules/cfork/blob/master/index.js
The text was updated successfully, but these errors were encountered: