Server IP : 85.214.239.14 / Your IP : 3.15.237.229 Web Server : Apache/2.4.62 (Debian) System : Linux h2886529.stratoserver.net 4.9.0 #1 SMP Tue Jan 9 19:45:01 MSK 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.18 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : OFF | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /proc/2/root/proc/3/root/lib/node_modules/npm/node_modules/foreground-child/dist/esm/ |
Upload File : |
// this spawns a child process that listens for SIGHUP when the // parent process exits, and after 200ms, sends a SIGKILL to the // child, in case it did not terminate. import { spawn } from 'child_process'; const watchdogCode = String.raw ` const pid = parseInt(process.argv[1], 10) process.title = 'node (foreground-child watchdog pid=' + pid + ')' if (!isNaN(pid)) { let barked = false // keepalive const interval = setInterval(() => {}, 60000) const bark = () => { clearInterval(interval) if (barked) return barked = true process.removeListener('SIGHUP', bark) setTimeout(() => { try { process.kill(pid, 'SIGKILL') setTimeout(() => process.exit(), 200) } catch (_) {} }, 500) }) process.on('SIGHUP', bark) } `; /** * Pass in a ChildProcess, and this will spawn a watchdog process that * will make sure it exits if the parent does, thus preventing any * dangling detached zombie processes. * * If the child ends before the parent, then the watchdog will terminate. */ export const watchdog = (child) => { let dogExited = false; const dog = spawn(process.execPath, ['-e', watchdogCode, String(child.pid)], { stdio: 'ignore', }); dog.on('exit', () => (dogExited = true)); child.on('exit', () => { if (!dogExited) dog.kill('SIGKILL'); }); return dog; }; //# sourceMappingURL=watchdog.js.map