Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
killing a node.js child process with infinite loop
while(true) {
// 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(){
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');
}, 2000);
Copy link

knyga commented Sep 29, 2018

Check the harakiri repo. This module has similar idea to manage process health.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment