简体   繁体   English

Node JS中的子进程是否需要手动杀死?

[英]Does the child process in Node JS need to be killed manually?

I have a child process.我有一个子进程。

The Questions is:问题是:

  • Does the child process need to be killed manually?子进程是否需要手动杀死?
  • Will the child process continue to run even if my application is shut down?即使我的应用程序关闭,子进程会继续运行吗?
  • Will the child process automatically killed if the main application dies?如果主应用程序死了,子进程会自动杀死吗?

Example例子

import { spawn } from 'child_process'

const backTaskProcess = spawn(process.execPath, ['back-task.js'], {
  cwd: process.cwd(),
})

// Do i need to disabled it manually?
process.on('SIGQUIT', () => {
  backTaskProcess.kill('SIGQUIT')
})

No, no, and yes.不,不,是的。 You don't need to kill it manually, unless you use detached: true in the options.你不需要手动杀死它,除非你在选项中使用detached: true There are exceptions when using fork() , but that doesn't apply to your code.使用 fork() 时有例外,但这不适用于您的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM