openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 2.2 kB
JavaScript
import{r as signalProcessTree}from"./kill-tree-CIjHhVfN.mjs";import{t as hasErrnoCode}from"./errno-DUBt6SQQ.mjs";import{t as scheduleAdoptedChildZombieReapAfterExit}from"./scoped-child-reaper-D-zM_mT7.mjs";import{o as isProcessGroupGoneByCensus,s as isProcessGroupGoneByCensusAsync}from"./service-child-group-ownership-CzRiJZ_p.mjs";
//!src/process/child-process-tree.ts
function shouldDetachChildForProcessTree(){return process.platform!==`win32`}function isDeniedProcessGroupProbe(e,t=0){if(process.platform!==`linux`||!hasErrnoCode(e,`EPERM`))return false;try{process.kill(-4194305,t);return false}catch(e){return hasErrnoCode(e,`EPERM`)}}function probeProcessGroup(e){try{process.kill(-e,0);return`alive`}catch(e){if(hasErrnoCode(e,`ESRCH`))return`gone`;return isDeniedProcessGroupProbe(e)?`denied`:`alive`}}function isProcessGroupGoneByKernel(e){return probeProcessGroup(e)===`gone`}function isProcessGroupGone(e){const t=probeProcessGroup(e);return t===`gone`||t===`denied`&&isProcessGroupGoneByCensus(e)}async function isProcessGroupGoneAsync(e){const t=probeProcessGroup(e);return t===`gone`||t===`denied`&&await isProcessGroupGoneByCensusAsync(e)}async function isChildProcessTreeAliveAsync(e){if(typeof e.pid!==`number`||e.pid<=0)return false;return shouldDetachChildForProcessTree()?!await isProcessGroupGoneAsync(e.pid):isChildProcessTreeAlive(e)}function isChildProcessTreeAlive(e){if(typeof e.pid!==`number`||e.pid<=0)return false;if(shouldDetachChildForProcessTree())return!isProcessGroupGone(e.pid);try{process.kill(e.pid,0);return true}catch(e){return!hasErrnoCode(e,`ESRCH`)}}function signalChildProcessTree(e,t,n){if(typeof e.pid===`number`&&e.pid>0){const r=shouldDetachChildForProcessTree();signalProcessTree(e.pid,t,{detached:r,onComplete:n});scheduleAdoptedChildZombieReapAfterExit(e,r);return}try{e.kill(t)}finally{n?.()}}function forceKillChildProcessTree(e){signalChildProcessTree(e,`SIGKILL`)}export{isProcessGroupGone as a,shouldDetachChildForProcessTree as c,isDeniedProcessGroupProbe as i,signalChildProcessTree as l,isChildProcessTreeAlive as n,isProcessGroupGoneAsync as o,isChildProcessTreeAliveAsync as r,isProcessGroupGoneByKernel as s,forceKillChildProcessTree as t};