我是新手,试图学习Node.js,并努力了解如何正确覆盖SIGINT / SIGTERM处理程序,以安全地处理派生子进程中的资源。
Nodejs documentation指出:
'SIGTERM'和'SIGINT'在非Windows平台上具有默认处理程序,这些处理程序在退出代码128 +信号编号之前会重置终端模式。如果这些信号之一已安装侦听器,则将删除其默认行为(Node.js不再退出)。
看起来,如果为SIGINT或SIGTERM实现了侦听器,则将删除两个默认处理程序。
如何通过触发SIGTERM处置资源的附加功能来模仿SIGINT的默认行为?
当前,我有:
/**
* Signal handlers
*/
process.on('SIGTERM', (signal, code) => {
signalExit(code, me);
});
process.on('SIGINT', (signal, code) => {
signalExit(code, me);
});
/**
* Reset the terminal, dispose of resources and exit with code 128+exitCode
* @param {number} exitCode - Exit code
* @param {Process} me - Process resource manager
*/
function signalExit(exitCode, me) {
process.stdout.write('\x1Bc');
dispose(me);
process.exit(128 + exitCode);
}
这正是我想要的,因为在退出进程的同时SIGINT和SIGTERM都处理了资源。
但是,我不确定以下内容: