-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmaster.js
48 lines (38 loc) · 1.27 KB
/
master.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/**
* Created by weiqiujuan on 17-7-30.
*/
const fs = require('fs');
const child_process = require('child_process');
for(var i=0; i<3; i++) {
var workerProcess = child_process.exec('node support.js '+i,
function (error, stdout, stderr) {
if (error) {
console.log(error.stack);
console.log('Error code: '+error.code);
console.log('Signal received: '+error.signal);
}
console.log('stdout: ' + stdout);
console.log('stderr: ' + stderr);
});
workerProcess.on('exit', function (code) {
console.log('子进程已退出,退出码 '+code);
});
}
for(var i=0;i<3;i++){
var workerProcess = child_process.spawn('node',['support.js',i])
workerProcess.stdout.on('data',function(data){
console.log('stdout:'+data);
});
workerProcess.stderr.on('data',function (data) {
console.log('stderr:'+data);
});
workerProcess.on('close',function (code) {
console.log('子进程已经退出,退出码'+code);
});
}
for(var i=0;i<3;i++){
var worker_process = child_process.fork("support.js",[i]);
worker_process.on('close',function (code) {
console.log('子进程已经退出,退出码 '+code);
});
}