nodejs child process

时间:2024-03-30 19:34:43
//Create child process
var thread = require('child_process'); var msg = thread.fork(__dirname + '/child.js',['asdasd']); msg.on('message', function (m) {
debugger;
console.log('PARENT got message:', m);
}); msg.on('close', function () {
//3
debugger;
})
msg.on('disconnect', function () {
//1
debugger;
})
msg.on('exit', function () {
//2
debugger;
})
msg.send('asd');
setTimeout(function () {
msg.kill();
}, 5000);

  

child.js

process.on('message', function (m,arr) {
setInterval(function () {
process.exit(1);
},2000)
});