事件:'exit'


【Event: 'exit'

  • code <number> 如果子进程自行退出,则为退出代码;如果子进程因信号终止,则为 null
  • signal <string> 导致子进程终止的信号;如果子进程不是由于信号而终止,则为 null

'exit' 事件在子进程结束后触发。如果进程正常退出,code 表示进程的最终退出代码,否则为 null。如果进程因为收到信号而终止,signal 是该信号的字符串名称,否则为 null。二者中总有一个不为 null

【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.】

'exit' 事件被触发时,子进程的 stdio 流可能仍然是打开的。

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

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

【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.】

请参阅 waitpid(2)

【See waitpid(2).】