kill all child_process when node process is killed

后端 未结 2 1271
孤城傲影
孤城傲影 2021-02-05 04:56

How do i make sure all child_process are killed when the parent process is killed. I have something like the below one.

Even when the node process is kill i see that F

2条回答
  •  悲&欢浪女
    2021-02-05 05:13

    You need to listen for the process exit event and kill the child processes then. This should work for you:

    var args = "ffmpeg -i in.avi out.avi"
    var a = child_process.exec(args , function(err, stdout,stderr){});
    
    var b = child_process.exec(args , function(err, stdout,stderr){});
    
    process.on('exit', function () {
        a.kill();
        b.kill();
    });
    

提交回复
热议问题