subprocess.ref()
新增于: v0.7.10
在调用 subprocess.unref() 后调用 subprocess.ref() 将恢复子进程的已删除引用计数,从而强制父进程等待子进程退出后再退出自身。
\Calling subprocess.ref() after making a call to subprocess.unref() will
restore the removed reference count for the child process, forcing the parent
process to wait for the child process to exit before exiting itself.
const { spawn } = require('node:child_process'); const process = require('node:process'); const subprocess = spawn(process.argv[0], ['child_program.js'], { detached: true, stdio: 'ignore', }); subprocess.unref(); subprocess.ref();import { spawn } from 'node:child_process'; import process from 'node:process'; const subprocess = spawn(process.argv[0], ['child_program.js'], { detached: true, stdio: 'ignore', }); subprocess.unref(); subprocess.ref();