如何以编程方式closures节点程序并重新启动?

我需要closures节点程序并重新启动。 我想在自己的程序中做到这一点,而不必像使用永远需要安装的东西,如果可能的话。 我知道我可以使用process.exit()来closures程序,但是我能想到的任何东西都会打开它,我可以从节点内启动,在process.exit()完成之前就会被kill掉。 有没有一种方法,我没有看到在我退出之前,从stream程中分离出一个EXEC调用? 任何其他的想法? 我必须吸起来,永远使用吗?

快速和肮脏,不是很好testing:

var child_process = require('child_process'); process.on('SIGINT', function() { console.log('restarting...'); child_process.fork(__filename); // TODO: pass args... process.exit(0); }); console.log('Running as %d', process.pid); setTimeout(function(){}, 1000000); // just some code to keep the process running 
Interesting Posts