UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

1 lines • 1.96 kB
import{t as e}from"./fs-safe-copy.worker-errno-CsW5NI8i.mjs";import{d as t,h as n,u as r}from"./fs-safe-copy.worker-service-child-group-ownership-D9CheQE8.mjs";import i,{readFile as a,readdir as o}from"node:fs/promises";import{inspectChildWaitState as s,isSupported as c,reapChild as l}from"@openclaw/proc-safe/reaper";const u=/* @__PURE__ */ new WeakSet,d=/* @__PURE__ */ new Map,f=3e4;let p,m=0,h=!1;function schedule(e){let t=performance.now()+e;p&&m<=t||(clearTimeout(p),m=t,p=setTimeout(()=>void tick(),e).unref())}function onExit(){schedule(25)}async function tick(){if(p=void 0,h)schedule(25);else{h=!0;try{for(let[t,n]of d)if(performance.now()>=n)d.delete(t);else try{process.kill(-t,0)}catch(n){e(n,`ESRCH`)&&d.delete(t)}if(d.size===0)return;for(let e of await o(`/proc/self/task`)){let t;try{t=await a(`/proc/self/task/${e}/children`,`utf8`)}catch{continue}for(let e of t.trim().split(/\s+/u).filter(Boolean)){let t=Number(e),n;try{n=await a(`/proc/${t}/stat`,`utf8`)}catch{continue}let[r,i,o]=n.slice(n.lastIndexOf(`)`)+2).split(` `);if(d.has(Number(o))&&t!==Number(o)&&Number(i)===process.pid&&r===`Z`)try{if(!c()){d.clear();return}s(t).kind===`exited`&&l(t)}catch{}}}}catch{}finally{h=!1,d.size>0?schedule(1e3):(clearTimeout(p),p=void 0,process.off(`SIGCHLD`,onExit))}}}function scheduleAdoptedChildZombieReapAfterExit(e,t,n=f){if(process.platform!==`linux`||!t||e.pid===void 0||u.has(e))return;let r=e.pid;u.add(e);let start=()=>{d.size===0&&process.on(`SIGCHLD`,onExit),d.set(r,performance.now()+Math.max(f,n)),onExit()};e.exitCode!==null||e.signalCode!==null?start():e.once(`exit`,start)}function readCommandProcessStartTime(e,a={}){return process.platform!==`linux`&&process.platform!==`android`?a.instance?t(e):r(e):i.readFile(`/proc/${e}/stat`,`utf8`).then(t=>a.child&&(a.child.exitCode!=null||a.child.signalCode!=null)?null:n(e,t)?.startedAt??null,()=>null)}export{scheduleAdoptedChildZombieReapAfterExit as n,readCommandProcessStartTime as t};