本文介绍了当节点进程被杀死时,杀死所有child_process的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当父进程被杀死时,我如何确保所有child_process被杀死。
我有类似下面的东西。
How do i make sure all child_process are killed when the parent process is killed.I have something like the below one.
即使节点进程被杀死,我也看到FFMPEG继续运行并生成了out.avi。节点进程退出后,如何停止FFMPEG的运行。
Even when the node process is kill i see that FFMPEG continues to run and the out.avi is generated. How can i stop FFMPEG from running after the node process exits.
var args = "ffmpeg -i in.avi out.avi"
child_process.exec(args , function(err, stdout,stderr){});
child_process.exec(args , function(err, stdout,stderr){});
推荐答案
您需要侦听进程退出事件并杀死然后子进程处理。这应该对您有用:
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();
});
这篇关于当节点进程被杀死时,杀死所有child_process的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!