MCPcopy Index your code
hub / github.com/forloopcodes/contextplus / startParentMonitor

Function startParentMonitor

src/core/process-lifecycle.ts:114–139  ·  view source on GitHub ↗
(options: ParentMonitorOptions)

Source from the content-addressed store, hash-verified

112}
113
114export function startParentMonitor(options: ParentMonitorOptions): () => void {
115 if (!Number.isFinite(options.parentPid) || options.parentPid <= 1 || options.parentPid === process.pid) {
116 return () => { };
117 }
118
119 const pollIntervalMs = Math.max(MIN_PARENT_POLL_MS, Math.floor(options.pollIntervalMs ?? DEFAULT_PARENT_POLL_MS));
120 const isAlive = options.isProcessAlive ?? isProcessAlive;
121 let stopped = false;
122
123 const stop = (): void => {
124 if (stopped) return;
125 stopped = true;
126 clearInterval(interval);
127 };
128
129 const interval = setInterval(() => {
130 if (stopped) return;
131 if (process.ppid !== options.parentPid || !isAlive(options.parentPid)) {
132 stop();
133 options.onParentExit();
134 }
135 }, pollIntervalMs);
136
137 unrefHandle(interval);
138 return stop;
139}
140
141export async function runCleanup(options: CleanupOptions): Promise<void> {
142 options.cancelEmbeddings?.();

Callers 2

mainFunction · 0.85

Calls 2

stopFunction · 0.85
unrefHandleFunction · 0.85

Tested by

no test coverage detected