MCPcopy Create free account
hub / github.com/modem-dev/hunk / parseLinuxStatus

Function parseLinuxStatus

scripts/daemon-memory-check.ts:187–207  ·  view source on GitHub ↗
(pid: number)

Source from the content-addressed store, hash-verified

185}
186
187function parseLinuxStatus(pid: number) {
188 if (process.platform !== "linux") {
189 return null;
190 }
191
192 try {
193 const status = readFileSync(`/proc/${pid}/status`, "utf8");
194 const valueKb = (name: string) => {
195 const match = status.match(new RegExp(`^${name}:\\s+(\\d+)\\s+kB`, "m"));
196 return match ? Number(match[1]) * 1024 : null;
197 };
198 return {
199 rssBytes: valueKb("VmRSS") ?? 0,
200 // External process probes cannot reliably read Bun's JS heap; RSS is the leak signal here.
201 heapBytes: null,
202 highWaterRssBytes: valueKb("VmHWM"),
203 };
204 } catch {
205 return null;
206 }
207}
208
209async function readProcessMemory(pid: number) {
210 const linux = parseLinuxStatus(pid);

Callers 1

readProcessMemoryFunction · 0.85

Calls 1

valueKbFunction · 0.85

Tested by

no test coverage detected