Node.JS child processes are killed when a parent dies

I use child_process.spawn () to run a script from my Node.JS application running on Ubuntu. As far as I know, standard * nix forked or spawned processes usually don’t die when the parent dies, but when spawning processes from Node.JS spawn, they seem to die when my application crashes or ctrl-c is interrupted, etc.

Why is this a way around this? I cannot find any obvious option in the child_process API.

My application launches several rather lengthy tasks that must be performed in the background, and if my node server crashes or restarts for some other reason, I do not want to interrupt the tasks, instead I want the node server to return and gracefully resume monitoring the execution of these running tasks.

+8
linux child-process
source share
1 answer

you need to set the disabled option

If a separate parameter is set, the child process will be executed by the leader of the new technology group. This allows the child to continue working after the parent leaves.

var child = spawn('prg', [], { detached: true, stdio: [ 'ignore', out, err ] }); 
+17
source share

All Articles