Skip to content

Instantly share code, notes, and snippets.

@lqqyt2423
Last active February 26, 2019 12:16
Show Gist options
  • Save lqqyt2423/a79a4c359abd0e101ab990b9eda1a0f4 to your computer and use it in GitHub Desktop.
Save lqqyt2423/a79a4c359abd0e101ab990b9eda1a0f4 to your computer and use it in GitHub Desktop.
进程间通信 node
// IPC
// parent.js
'use strict';
const cp = require('child_process');
const n = cp.fork('./sub.js');
n.on('message', function (m) {
console.log('PARENT got message:', m);
});
n.send({ hello: 'world' });
// sub.js
'use strict';
process.on('message', function (m) {
console.log('CHILD got messae:', m);
});
process.send({ foo: 'bar' });
process.send('hello from child');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment