'exit' 事件


  • worker <cluster.Worker>
  • code <number> 如果其正常退出,则为退出码。
  • signal <string> 造成进程被终止的信号的名称(例如 'SIGHUP')。

当任何工作进程死亡时,则集群模块将触发 'exit' 事件。

这可用于通过再次调用 .fork() 来重新启动工作进程。

cluster.on('exit', (worker, code, signal) => {
  console.log('worker %d died (%s). restarting...',
              worker.process.pid, signal || code);
  cluster.fork();
});

参见 child_process 事件: 'exit'

  • worker <cluster.Worker>
  • code <number> The exit code, if it exited normally.
  • signal <string> The name of the signal (e.g. 'SIGHUP') that caused the process to be killed.

When any of the workers die the cluster module will emit the 'exit' event.

This can be used to restart the worker by calling .fork() again.

cluster.on('exit', (worker, code, signal) => {
  console.log('worker %d died (%s). restarting...',
              worker.process.pid, signal || code);
  cluster.fork();
});

See child_process event: 'exit'.