-
-
Save Jarred-Sumner/54990c8de079b90f5eca797c3894480b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| import { spawn as nodeSpawn } from "child_process"; | |
| import { fileURLToPath } from "url"; | |
| const __filename = fileURLToPath(import.meta.url); | |
| async function spawn() { | |
| return new Promise((resolve, reject) => { | |
| const proc = nodeSpawn("cat", [__filename], { | |
| stdio: ["ignore", "ignore", "ignore"], | |
| shell: false, | |
| }); | |
| proc.on("exit", code => { | |
| resolve(); | |
| }); | |
| proc.on("error", err => { | |
| reject(err); | |
| }); | |
| }); | |
| } | |
| async function spawn100() { | |
| const procs = []; | |
| for (let i = 0; i < 100; i++) { | |
| procs.push(spawn()); | |
| } | |
| await Promise.all(procs); | |
| } | |
| var i = 0; | |
| const fmt = new Intl.NumberFormat(); | |
| while (i <= 1000) { | |
| const memUsage = (process.memoryUsage.rss() / 1024 / 1024) | 0; | |
| console.log( | |
| `\x1b[36mRSS:\x1b[0m \x1b[33m${memUsage}MB\x1b[0m \x1b[36mafter\x1b[0m \x1b[32m${fmt.format(i++ * 100)}\x1b[0m \x1b[36m\x1b[0m`, | |
| ); | |
| await spawn100(); | |
| } |
so many cats
meow
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Kill the child