Skip to content

Instantly share code, notes, and snippets.

@bboozzoo
Created October 28, 2022 16:15
Show Gist options
  • Save bboozzoo/da03f66b015b74496d469d02bf4000bb to your computer and use it in GitHub Desktop.
Save bboozzoo/da03f66b015b74496d469d02bf4000bb to your computer and use it in GitHub Desktop.
function log(message) {
console.log(`[${process.pid}][${Date.now()}] ${message}`);
}
if (process.argv[2] === 'child') {
log("child");
} else {
const { fork } = require('node:child_process');
const controller = new AbortController();
log("forking");
let before_fork = Date.now();
const child = fork(__filename, ['child']);
log(`child PID: ${child.pid}`);
child.on('exit', (code, signal) => {
let child_exited = Date.now();
log("child exited");
let took = (child_exited - before_fork) / 1000;
log(`took ${took}s`);
process.exit();
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment