'exit' 事件


  • code <number> 如果子进程自己退出,则为退出码。
  • signal <string> 终止子进程的信号。

'exit' 事件在子进程结束后触发。 如果进程退出,则 code 为最终的进程退出码,否则为 null。 如果进程因收到信号而终止,则 signal 是信号的字符串名称,否则为 null。 两者之一将始终是非 null

'exit' 事件被触发时,子进程标准输入输出流可能仍处于打开状态。

Node.js 为 SIGINTSIGTERM 建立信号句柄,且 Node.js 进程不会因为收到这些信号而立即终止。 而是,Node.js 将执行一系列清理操作,然后重新触发已处理的信号。

参见 waitpid(2)

  • code <number> The exit code if the child exited on its own.
  • signal <string> The signal by which the child process was terminated.

The 'exit' event is emitted after the child process ends. If the process exited, code is the final exit code of the process, otherwise null. If the process terminated due to receipt of a signal, signal is the string name of the signal, otherwise null. One of the two will always be non-null.

When the 'exit' event is triggered, child process stdio streams might still be open.

Node.js establishes signal handlers for SIGINT and SIGTERM and Node.js processes will not terminate immediately due to receipt of those signals. Rather, Node.js will perform a sequence of cleanup actions and then will re-raise the handled signal.

See waitpid(2).