Skip to content

Instantly share code, notes, and snippets.

@bboozzoo
Created October 28, 2022 16:15
Show Gist options
  • Save bboozzoo/9913e60d72873f33176414cc5a314c3d to your computer and use it in GitHub Desktop.
Save bboozzoo/9913e60d72873f33176414cc5a314c3d 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', (_, _) => {
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