-
-
Save gotomypc/4012108 to your computer and use it in GitHub Desktop.
Node.js weirdness with child processes and signals
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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