I have two questions here:
is there any way to manage child_proccess (spawn) which running with nodejs?
suppose I have a script that starts do some functionality, I need to start the execution with socket.io event. I need to stop this execution with another socket io event.
the first idea that came through my mind was :
start execution command with spawn and store the PID of the job in Redis. in the stop event, get PID from Redis and kill that process with another spawn with below command:
kill = spawn(`kill ${PID}`)
but os kernel does not allow nodejs to kill that process unless nodejs runs with sudo command.I am the owner of that child_procces. why I can't stop that?
the second Idea is to use global variable :
io = ()=>{
let job = null;
socket.on("start", ()=>{
job = spawn("path/to/my/script")
})
socket.on("stop", ()=>{
job.kill() // or procces.kill(job.pid)
})
}
so I am so confused about managing child processes with nodejs.