При выполнении worker = cluster.fork()
я хотел бы пересылать потоки stdout и stderr в основной процесс Node.js.
Как я могу это сделать?
Я пробовал делать:
worker = cluster.fork();
worker.process.stdout.pipe(process.stdout)
// ^ this is null
Обходным путем было бы использование сообщений, но я хочу иметь возможность передавать контент.
worker.on("message", function(msg){
console.log("Master says:" + msg);
});
...
worker.send({message:'hello'});
Как я могу получить доступ к этапу развертки процесса/кластера?
см. код ниже
для мастер-процесса:
const cluster = require('cluster');
cluster.settings.stdio=[0, 1, 2, 'ipc'];
cluster.settings.silent = true; //Whether or not to send output to parent stdio. Default: false.
cluster.settings.exec = './hello' //the forked process file path
const childW = cluster.fork();
const child = childW.process;
для раздвоенного процесса: ./hello.js
console.log('hello')