/** * @file Reading the process table as labelled rows, and spotting a wrapper * that has recursed into itself. * A shim that resolves its target through the same PATH it was found on can * exec a binary that IS the shim. Each generation spawns the next, so the * chain grows without bound until memory runs out. Every link has a live * parent, which is why the usual orphan and idle heuristics never see it: * nothing in the chain is orphaned, nothing is idle, and no single process * is large. * The signature is structural. Three consecutive processes carrying the * same label cannot be legitimate, because real nesting always puts a * different program in between (a shim spawns a package manager, which * spawns the shim again). Two levels stay legitimate on purpose: a shim * spawning the real binary behind it is an ordinary pair. */ export interface ProcessTreeRow { command: string; pid: number; ppid: number; } /** * The number of consecutive same-label processes that marks a recursion. * Two is an ordinary shim-and-binary pair; three cannot be. */ export declare const SELF_NEST_DEPTH = 3; /** * Every row that sits at the bottom of a same-label run of `depth`. The * deepest links come first, so a caller signalling them in order never * reparents a survivor onto init mid-sweep. */ export declare function findSelfNestedProcesses(rows: readonly ProcessTreeRow[], labelOf: (row: ProcessTreeRow) => string | undefined, depth?: number): ProcessTreeRow[]; /** * Whether `row` sits at the bottom of a run of `depth` consecutive processes * that all carry the same label. * * `labelOf` names the family a row belongs to and returns `undefined` for a * row that belongs to none. Rows with no label are never self-nested, so a * caller can pass a classifier that recognizes only the wrappers it cares * about and ignore everything else. */ export declare function isSelfNestedProcess(rows: readonly ProcessTreeRow[], row: ProcessTreeRow, labelOf: (row: ProcessTreeRow) => string | undefined, depth?: number): boolean; /** * Snapshot the POSIX process table as rows of `pid`, `ppid`, and the full * command. One `ps` call, parsed once: walking the tree needs the whole table * anyway, and re-reading it per-level would let processes move between reads. * * Returns an empty array when `ps` is unavailable or fails, so a caller sees * "nothing to act on" rather than a partial table it might act on wrongly. */ export declare function readProcessTree(): ProcessTreeRow[];