0

我生了很多孩子

var spawn = require('child_process').spawn,
  newProcess1 = spawn('node', ['File1.js']),
  newProcess2 = spawn('node', ['File2.js']),
  newProcess3 = spawn('node', ['File3.js']);

它将并行运行。如果 newProcess1 失败,则 newProcess2 和 newProcess3 如果尚未启动,则必须停止或终止。

如何杀死一个子进程?

4

1 回答 1

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

http://nodejs.org/api/child_process.html

于 2013-09-05T07:09:53.123 回答