fork_ping.js 426 B

123456789101112131415161718
  1. const childProcess = require('node:child_process');
  2. const path = require('node:path');
  3. process.on('uncaughtException', function (error) {
  4. process.send(error.stack);
  5. });
  6. const child = childProcess.fork(path.join(__dirname, '/ping.js'));
  7. process.on('message', function (msg) {
  8. child.send(msg);
  9. });
  10. child.on('message', function (msg) {
  11. process.send(msg);
  12. });
  13. child.on('exit', function (code) {
  14. process.exit(code);
  15. });