Multithreading 如何杀死并行运行的子进程

Multithreading 如何杀死并行运行的子进程,multithreading,node.js,asynchronous,child-process,Multithreading,Node.js,Asynchronous,Child Process,我生了很多孩子 var spawn = require('child_process').spawn, newProcess1 = spawn('node', ['File1.js']), newProcess2 = spawn('node', ['File2.js']), newProcess3 = spawn('node', ['File3.js']); 它将并行运行。如果newProcess1失败,则必须停止newProcess2和newProcess3,如果尚未启动,则必须

我生了很多孩子

var spawn = require('child_process').spawn,
  newProcess1 = spawn('node', ['File1.js']),
  newProcess2 = spawn('node', ['File2.js']),
  newProcess3 = spawn('node', ['File3.js']);
它将并行运行。如果newProcess1失败,则必须停止newProcess2和newProcess3,如果尚未启动,则必须将其终止

如何杀死一个子进程

newProcess1.on('close', function (code) { 
  console.log('child process ' + newProcess1.pid + ' exited with code ' + code); 
  newProcess2.kill();
  newProcess3.kill();
});

这个如何
newProcess1.kill()@Amol M Kulkarni newProcess1将失败它应该与newProcess2和NewProcess3同时终止,在代码的哪部分我应该提到newProcess2.kill();newProcess3.kill()?这是我调用所有进程newProcess.stdout.on('data',function(data){console.log('stdout:'+data);})的方式;newProcess.stderr.on('data',函数(data){console.log('stderr:'+data);});newProcess.on('close',函数(代码){console.log('child process'+newProcess.pid+'exit with code'+code);});在process1的close回调中杀死它们是否可以在此代码中调用外部文件,而不是将字符串传递给子级。var cp=需要(“子流程”);var child=cp.fork(“./worker”);on('message',function(m){//Receive results from child process console.log('received:'+m);});//发送子进程一些工作子进程。发送('Please up case this string');