为什么childprocess不能捕捉到“SIGINT”

father.js var spawn = require('child_process').spawn; var child = spawn('node',['child.js']); setInterval(function(){ child.kill('SIGINT'); },2000); child.on('exit',function(code,signal){ console.log('process exit '+code+' '+signal); }); child.js process.stdin.resume(); process.on('SIGINT', function() { console.log('Got SIGINT. Press Control-D to exit.'); }); 

节点版本:0.10.17

为什么childprocess不能捕捉到“SIGINT”? 但是如果你单独运行节点child.js,那么可以用ctrl + c来终止cmd。

它确实得到了SIGINT ! 只是你没有听到subprocess的输出。 在father.js中添加这一行来查看它。

 child.stdout.pipe(process.stdout);