Skip to content

Instantly share code, notes, and snippets.

@gotomypc
Forked from ggreer/example.js
Created November 4, 2012 14:20
Show Gist options
  • Select an option

  • Save gotomypc/4012108 to your computer and use it in GitHub Desktop.

Select an option

Save gotomypc/4012108 to your computer and use it in GitHub Desktop.
Node.js weirdness with child processes and signals
var blah = setTimeout(function () {
console.log('example dying');
}, 30000);
var blah2 = setTimeout(function () {
console.log('example debugging');
process.stdout.write('example debugging');
// debugger;
}, 5000);
process.on('SIGINT', function() {
console.log('example got sigint');
process.stdout.write('example got sigint');
});
process.on('SIGTERM', function() {
console.log('example got sigterm');
process.stdout.write('example got sigterm');
});
process.on('exit', function() {
console.log('example exiting');
process.stdout.write('example exiting');
});
process.stdout.write('example writing to stdout');
ggreer@carbon:~/Desktop/2474314% node signals.js
debug>< debugger listening on port 5858
debug>connecting... ok
debug>
unhandled res:{}
debug>break in example.js:2
1
2 var blah = setTimeout(function () {
3 console.log('example dying');
4 }, 30000);
debug> c
debug> debug>< example writing to stdout
debug>< example debugging
debug>< example debugging
debug> killing child
child exited
^Cgot sigint
var child_process = require('child_process');
process.on('SIGINT', function() {
console.log('got sigint');
// child.kill('SIGINT');
});
var blah = setTimeout(function () {
console.log('killing child');
child.kill('SIGINT');
}, 10000);
//var child = child_process.spawn('dtruss', ['node', 'debug', 'example.js']);
var child = child_process.spawn('node', ['debug', 'example.js']);
child.stderr.pipe(process.stderr, { end: false });
child.stdout.pipe(process.stdout, { end: false });
/*child.stdout.on('data', function(data) {
console.log(data.toString());
});
*/
process.stdin.pipe(child.stdin, { end: false });
process.stdin.resume();
child.on('SIGINT', function() {
console.log('child got sigint');
});
child.on('exit', function() {
console.log('child exited');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment