@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
36 lines • 1.99 kB
TypeScript
/** One row of the whole-table read; `state` is `"Z"` for zombies, `"U"` otherwise. */
export interface ProcessTableRow {
readonly pid: number;
readonly ppid: number;
readonly state: string;
/** Resident memory in kilobytes; 0 where the kernel reports none (zombies). */
readonly rssKb: number;
}
/** Reads the whole process table without spawning anything, or `undefined` when it cannot. */
export type ProcessTableReader = () => readonly ProcessTableRow[] | undefined;
export interface ProcessTableReaderOptions {
/**
* Size of the first `sysctl` buffer. The reader grows geometrically from here on a
* short read; tests use a tiny value to force the growth path. Production keeps the
* default, sized for the busiest observed table.
*/
readonly initialTableBytes?: number;
}
/**
* Loads the platform reader once per process. Node (and any platform without bindings)
* resolves to `undefined`: the status surface then reports `null` fields rather than
* falling back to a `ps` child, because a read that spawns a probe is the bug this module
* exists to prevent.
*/
export declare function loadProcessTableReader(platform?: NodeJS.Platform, options?: ProcessTableReaderOptions): Promise<ProcessTableReader | undefined>;
/**
* Parses `rowCount` `kinfo_proc` rows out of a `sysctl(KERN_PROC_ALL)` buffer.
*
* Fails closed: the parsed table must describe THIS process - its row exists, its ppid
* equals the kernel's own view (`process.ppid`), and it is not a zombie - or the caller
* gets `undefined`. The offsets above are pinned by measurement on darwin arm64; if a
* future SDK or arch moves the layout, that drift surfaces here as a failed self-check and
* the status reports `null`, never a plausible wrong table.
*/
export declare function parseKernelProcessTable(table: Uint8Array, rowCount: number, residentKb: (pid: number) => number): readonly ProcessTableRow[] | undefined;
//# sourceMappingURL=host-process-table.d.ts.map