Node.JS 父进程死亡时子进程被杀死
Node.JS child processes being killed when parent dies
我在 Ubuntu 上使用 child_process.spawn() 从我的 Node.JS 应用程序 运行ning 启动脚本。据我所知,标准的 forked 或 spawned *nix 进程通常不会在父进程死亡时死亡,但是当从 Node.JS 产生进程时,它们似乎在我的应用程序崩溃时被杀死,或者被 ctrl- 中止c等
为什么会这样,有没有办法解决这个问题?我似乎无法在 child_process API.
中找到任何明显的选项
我的应用程序启动了一些相当长的 运行ning 任务,这些任务应该 运行 在后台进行,如果我的节点服务器崩溃或由于其他原因重新启动,我不想中断任务,相反,我希望节点服务器重新启动并优雅地恢复监视那些 运行ning 任务的进度。
您需要设置分离选项
If the detached option is set, the child process will be made the
leader of a new process group. This makes it possible for the child to
continue running after the parent exits.
var child = spawn('prg', [], {
detached: true,
stdio: [ 'ignore', out, err ]
});
我在 Ubuntu 上使用 child_process.spawn() 从我的 Node.JS 应用程序 运行ning 启动脚本。据我所知,标准的 forked 或 spawned *nix 进程通常不会在父进程死亡时死亡,但是当从 Node.JS 产生进程时,它们似乎在我的应用程序崩溃时被杀死,或者被 ctrl- 中止c等
为什么会这样,有没有办法解决这个问题?我似乎无法在 child_process API.
中找到任何明显的选项我的应用程序启动了一些相当长的 运行ning 任务,这些任务应该 运行 在后台进行,如果我的节点服务器崩溃或由于其他原因重新启动,我不想中断任务,相反,我希望节点服务器重新启动并优雅地恢复监视那些 运行ning 任务的进度。
您需要设置分离选项
If the detached option is set, the child process will be made the leader of a new process group. This makes it possible for the child to continue running after the parent exits.
var child = spawn('prg', [], {
detached: true,
stdio: [ 'ignore', out, err ]
});