Skip to content

Instantly share code, notes, and snippets.

@Jarred-Sumner
Created June 1, 2025 01:23
Show Gist options
  • Select an option

  • Save Jarred-Sumner/54990c8de079b90f5eca797c3894480b to your computer and use it in GitHub Desktop.

Select an option

Save Jarred-Sumner/54990c8de079b90f5eca797c3894480b to your computer and use it in GitHub Desktop.
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();
}
@pablodz

pablodz commented Jun 1, 2025

Copy link
Copy Markdown

Kill the child

@remorses

remorses commented Jun 1, 2025

Copy link
Copy Markdown

so many cats

@busybox11

Copy link
Copy Markdown

meow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment