import * as plugins from './smartexit.plugins.js'; import type { TProcessSignal } from './smartexit.types.js'; export type { TProcessSignal } from './smartexit.types.js'; export interface ISmartExitOptions { /** Completely disable logging for this instance. */ silent?: boolean; /** Time between POSIX SIGTERM and SIGKILL escalation. Defaults to 1,000ms. */ processTerminationGraceMs?: number; } /** A stable object identity representing one process root owned by SmartExit. */ export interface IProcessHandle { readonly pid?: number; } export interface IKillAllResult { processesKilled: number; cleanupFunctionsRan: number; } export interface IKillAllOptions { /** Abort the graceful interval and proceed directly to force-kill escalation. */ terminationSignal?: AbortSignal; } /** * SmartExit — process and cleanup tracker. * * Lightweight: the constructor does NOT register signal handlers. * Each instance auto-registers with ProcessLifecycle so that global * shutdown (triggered by ProcessLifecycle.install()) kills all tracked processes. * * Libraries should create instances freely. Only the application entry point * should call `ProcessLifecycle.install()`. */ export declare class SmartExit { private static readonly cleanupCallContext; private static releaseTrackedPidFromAllInstances; /** * Kill an owned process tree. On POSIX, the PID must identify a detached * process-group leader; Windows treats it as the taskkill root PID. */ static killTreeByPid(pidArg: number, signalArg?: TProcessSignal): Promise; /** * Node ChildProcess instances retained for backward compatibility. New * structural process handles are kept in the internal lifecycle registry. */ processesToEnd: plugins.lik.ObjectMap; cleanupFunctions: plugins.lik.ObjectMap<() => Promise>; private structuralProcessHandlesToEnd; private trackedPidGenerations; private processHandleTracking; private terminatingPidGenerations; private suppressTrackedPidSetNotifications; /** * PIDs tracked independently for tree-killing during shutdown. Removing a * PID from this public ownership set also withdraws it from later escalation. */ trackedPids: Set; private options; private killAllPromise; private killAllTerminationController; private killAllSignalDisposers; private ensureTrackedPidGeneration; private getProcessHandlesToEnd; private addProcessHandleToRegistry; private removeProcessHandleFromRegistry; private validateProcessHandlePid; private releaseTrackedPid; private log; constructor(optionsArg?: ISmartExitOptions); /** Register a PID-bearing process handle for cleanup on shutdown. */ addProcess(processHandleArg: IProcessHandle): void; /** Register an async cleanup function to run on shutdown. */ addCleanupFunction(cleanupFunctionArg: () => Promise): void; /** * Unregister the same process-handle object. On POSIX, group ownership remains when * descendants still exist under the tracked detached group leader PID. */ removeProcess(processHandleArg: IProcessHandle): void; /** * Run cleanup functions, then kill all tracked process trees. * Called by ProcessLifecycle during global shutdown. * Can also be called manually. */ killAll(optionsArg?: IKillAllOptions): Promise; private linkTerminationSignal; private waitForTerminationGrace; private runKillAll; /** Remove this instance from the global ProcessLifecycle registry. */ deregister(): void; }