// What /proc says about one process. Same-UID process identity: a pid plus // its start time names one process, so a recycled pid never matches. import { readFileSync } from "node:fs"; // `/proc//stat` field 22, the start time in clock ticks. Null when the // process is gone or has exited and waits to be reaped (state Z). export function startTimeOf(pid) { try { const raw = readFileSync(`/proc/${pid}/stat`, "utf8"); const fields = raw.slice(raw.lastIndexOf(")") + 2).split(" "); return fields[0] === "Z" ? null : fields[19]; } catch { return null; } } export function cmdlineOf(pid) { try { return readFileSync(`/proc/${pid}/cmdline`, "utf8").split("\0").filter(Boolean); } catch { return null; } } // The pids of pid's direct children, or [] when it has none or is gone. export function childrenOf(pid) { try { return readFileSync(`/proc/${pid}/task/${pid}/children`, "utf8").trim().split(/\s+/).filter(Boolean).map(Number); } catch { return []; } }