server.js
var http = require('http');
const PORT=8888;
var server = http.createServer(function (request, response) {
response.end ("pid:"+process.pid);
});
server.on("listening",function(){
console.log('process ',process.pid,"listen at ",PORT);
});
server.listen(PORT);
用cluster启动四个 Server.js进程
var cluster = require('cluster');
if (cluster.isMaster) {
require('os').cpus().forEach(function(){
cluster.fork();
});
}else {
require('./server.js');
}
用child_process 启用4个 server.js进程
const cp = require('child_process');
require('os').cpus().forEach(function(){
cp.fork("./server.js");
});
提示Error: listen EADDRINUSE :::8888
这是什么原因?