Dee*_*til 57 shell child-process node.js
使用shelljs创建了一个子进程
!/usr/bin/env node
require('/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);
子进程仍在运行..杀死父进程后
Mic*_*ang 71
如果您可以使用内置节点child_process.spawn,则可以向SIGINT子进程发送信号:
var proc = require('child_process').spawn('mongod');
proc.kill('SIGINT');
这样做的好处是主进程应该在所有子进程终止之前一直存在.
| 归档时间: | 
 | 
| 查看次数: | 57330 次 | 
| 最近记录: |