如何在nodejs中杀死子进程?
使用shelljs创建一个子进程
!/usr/bin/env noderequire('/usr/local/lib/node_modules/shelljs/global');
   fs = require("fs");  
   var child=exec("sudo mongod &",{async:true,silent:true});
   function on_exit(){
        console.log('Process Exit');
        child.kill("SIGINT");
        process.exit(0)
    }
    process.on('SIGINT',on_exit);
    process.on('exit',on_exit);
杀死父进程后,子进程仍在运行..
回答:
如果您可以使用node的内置child_process.spawn,则可以向SIGINT子进程发送信号:
var proc = require('child_process').spawn('mongod');proc.kill('SIGINT');
这样做的好处是,主进程应该一直徘徊,直到所有子进程都终止。
以上是 如何在nodejs中杀死子进程? 的全部内容, 来源链接: utcz.com/qa/429418.html
