當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Node.js ChildProcess subprocess.unref()用法及代碼示例

subprocess.unref()

添加於:v0.7.10

默認情況下,父級將等待分離的子級退出。要防止父級等待給定的subprocess 退出,請使用subprocess.unref() 方法。這樣做會導致父級的事件循環不將子級包含在其引用計數中,從而允許父級獨立於子級退出,除非子級和父級之間已建立 IPC 通道。

const { spawn } = require('node:child_process');

const subprocess = spawn(process.argv[0], ['child_program.js'], {
  detached: true,
  stdio: 'ignore'
});

subprocess.unref();

相關用法


注:本文由純淨天空篩選整理自nodejs.org大神的英文原創作品 subprocess.unref()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。