节点 – 在杀死事件

有没有办法在node.js进程被终止时运行一个函数?

这是我的目标(在C):

signal(SIGSEGV, sig_handler); void sig_handler(int sig) { if (sig == SIGSEGV) { // do stuff } } 

那么,是否有可能在node.js中做到这一点?

是的,

 process.on('SIGINT', function() { console.log('Got SIGINT. Press Control-D to exit.'); }); 

从文档中获取:

http://nodejs.org/api/process.html#process_signal_events