/** * One process orckit spawned, persisted so a LATER `orc start` can find it if * this orckit never got to clean up. * * Every other teardown path (Ctrl-C, SIGHUP, crash handlers) reaps children * from inside the running process. The one case none of them cover is orckit * itself being SIGKILLed — force-quit, OOM killer, `kill -9` — where no handler * runs at all and the detached process groups simply keep going. This file is * what makes those recoverable instead of invisible. */ export interface SessionRecord { name: string; pid: number; /** Process-group id (equal to pid — children are spawned detached). */ pgid: number; /** The command line as spawned; used to guard against PID reuse. */ command: string; /** * The process's descendants at the last refresh, each with the command it was * running. Recorded because the processes that actually strand themselves are * usually *grandchildren* — a Firebase functions runtime, an `ng serve` * worker — which reparent to init when their intermediate parent dies and are * then unreachable from `pid` alone. Commands are stored so a recycled PID is * never mistaken for a survivor. */ members?: Array<{ pid: number; command: string; }>; /** Process groups seen in the tree (a `set -m` script leads its own). */ pgids?: number[]; } export interface SessionFile { /** PID of the `orc start` process that owns these records. */ orckitPid: number; project: string; startedAt: number; processes: SessionRecord[]; } export declare function sessionFilePath(dir: string): string; /** * Persist the current set of live children. Best-effort: a read-only or * missing directory must never break a boot, so every failure is swallowed. */ export declare function writeSession(dir: string, session: SessionFile): void; export declare function readSession(dir: string): SessionFile | null; export declare function clearSession(dir: string): void; /** True when `pid` exists and we may signal it. */ export declare function isAlive(pid: number): boolean; /** * When `pid` started (`ps -o lstart=`), or null if it isn't running. A pid plus * its start time identifies a process across PID reuse. */ export declare function processStartTime(pid: number): Promise; /** * Records from a previous session whose process is STILL RUNNING and still * looks like the process we recorded. * * The identity check matters: PIDs are recycled, and a stale record must never * become a license to kill an unrelated process. A survivor counts only when * the live pid's current command line still matches what we recorded, so a * recycled pid running something else is dropped. */ export declare function findSurvivors(session: SessionFile): Promise; /** How many live processes a survivor record actually covers. */ export declare function survivorSize(record: SessionRecord): number; /** * Whether a live `ps` command line is plausibly the one we recorded. Orckit * spawns through `bash -c `, and `ps` renders that differently across * platforms (and truncates long lines), so an exact match is too strict — * containment either way is the right test. */ export declare function commandsMatch(recorded: string, live: string): boolean; /** * SIGTERM everything a recorded survivor still has running, then SIGKILL * whatever is left after `graceMs`. Returns true once nothing remains. * * Every target is re-verified against its recorded command HERE, at the kill * site, rather than trusting the record. The record can legitimately survive on * the strength of one descendant while its root PID has been recycled by an * unrelated program — signalling `record.pid`, let alone its whole process * group, would then kill a stranger. Only PIDs that still run what we recorded, * the groups those PIDs currently lead, and their live descendants are touched. */ export declare function killSurvivor(record: SessionRecord, graceMs?: number): Promise; //# sourceMappingURL=session-state.d.ts.map