-
-
Save romejiang/5e42b6d14d5dbba5f9cca06d709a2f70 to your computer and use it in GitHub Desktop.
killing a node.js child process with infinite loop
This file contains 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
while(true) { | |
console.log('blah'); | |
} |
This file contains 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
// to execute this test run `node parent.js` | |
var spawn = require('child_process').spawn; | |
console.log('Spawning child process'); | |
var child = spawn('node', ['child.js']); | |
child.on('exit', function(){ | |
clearTimeout(to); | |
console.log('Child exited!'); | |
}); | |
child.stdout.on('data', function (data) { | |
console.log('stdout: ' + data); | |
}); | |
child.stderr.on('data', function (data) { | |
console.log('stderr: ' + data); | |
}); | |
var to = setTimeout(function(){ | |
console.log('Sending sigkill'); | |
child.kill(); | |
}, 2000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment