2013-08-25 22 views
1
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为什么子进程不能赶上 'SIGINT'

为什么子进程不能赶上 'SIGINT'? 但如果你单独运行节点child.js,它可以为ctrl + c终止cmd的信号。

回答

1

它确实得到了SIGINT!只是你没有听到子进程输出。在father.js中添加此行以查看它。

child.stdout.pipe(process.stdout); 
+0

是的,你是right.I想念那个line.But仍然无法work.can尝试 – hugo

+0

我能够运行该程序,它表现出了SIGINT。每2秒后。 – user568109

+0

也许是节点的版本,你能告诉你的节点版本和运行平台吗? – hugo