Created
October 28, 2022 16:15
-
-
Save bboozzoo/9913e60d72873f33176414cc5a314c3d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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