Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

why childprocess can't catch 'SIGINT'

why childprocess can't catch 'SIGINT'

Problem

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.');
});

node version : 0.10.17

why Childprocess can't catch 'SIGINT'? but if you run node child.js alone, it can cathch signal for ctrl + c terminate cmd.

Problem courtesy of: hugo

Solution

It does get the SIGINT! Just that you are not listening to the child process output. Add this line in father.js to see it.

child.stdout.pipe(process.stdout);
Solution courtesy of: user568109

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

why childprocess can't catch 'SIGINT'

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×