Tuesday 23 April 2019

Coding Help: Pausing one child process when another is running

Hey guys,​I am having trouble trying to "kill" a constantly running child process (let's call it Child Process 1) at the start of another (Child Process 2). Once Child process 2 is complete, I would like Child process 1 to start back up again. I was thinking of adding a while loop to the code below, but did not know how to go about doing it properly.​var exec = require("child_process").exec; const execFile = require('child_process').exec; //Activates Child Process 1 on Startup const child = execFile('/path/executable1', function (error, stdout, stderr) { if (error) { throw error; return; } }); if (message === '!exec') { execFile.kill(); // Trying to kill Child Process 1 here, maybe add while loop instead? var process = exec('/path/executable2', (error, stdout, stderr) => { //activates Child Process 2 if (error) { console.error(`exec error: ${error}`); return; } console.log(\`stdout: ${stdout}\`); console.log(`stderr: ${stderr}`); }); }); As of now Child Process 1 activates on startup, Child Process 2 activates on !exec, but Child process 1 is also still running. Any advice?

Submitted April 23, 2019 at 05:01PM by Mketcha3

No comments:

Post a Comment