【nodejs--勉強01】:nodeのchild_process
2785 ワード
ちどり_process.fork(modulePath[,args][,options]) ちどり_process.forkはあなたにサブプロセスを作成させ、親プロセスと通信することができます.
例: 例をあげて
modulePath
String The module to run in the child args
Aray List of string argments options
Objectcwd
String Current working directory of the child process env
Object Evironment key-value pairs execPath
String Executable used to create the child process execArgv
Aray List of string argments passed to the executable silent
Boolean If true、stdin、stdout、and stder of the child will be piped to the parent、otherswise the will be inhersed from the parent、see the「pipe」and「inherit」options for spawdel.uid
Number Sets the user identity of the process.(See setuid(2).)gid
Number Sets the group identity of the process.(See setgid.)例:
main.js
var cp = require('child_process');
var n = cp.fork(__dirname + '/sub.js');
n.on('message', function(m) {
console.log('PARENT got message:', m);
});
n.send({ hello: 'child' });
sub.js
process.on('message', function(m) {
console.log('CHILD got message:', m);
});
process.send({ hello: 'father' });
そしてnode main.js
を通じて、メール・jsを実行した結果、以下のようになりました.CHILD got message: { hello: 'child' }
PARENT got message: { hello: 'father' }
ちどり_process.send(message[,sendenle])message
Object sendHandle Handle
object