Electron kill child_process.exec

Viewed 19405

I have an electron app that uses child_process.exec to run long running tasks. I am struggling to manage when the user exits the app during those tasks.

If they exit my app or hit close the child processes continue to run until they finish however the electron app window has already closed and exited.

Is there a way to notify the user that there are process still running and when they have finished then close the app window?

All I have in my main.js is the standard code:

// Quit when all windows are closed.
app.on('window-all-closed', function() {
    // On OS X it is common for applications and their menu bar
    // to stay active until the user quits explicitly with Cmd + Q
    if (process.platform != 'darwin') {
        app.quit();
    }
});

Should I be adding a check somewhere?

Thanks for your help

EDITED

I cannot seem to get the PID of the child_process until it has finished. This is my child_process code

var loader = child_process.exec(cmd, function(error, stdout, stderr) {
    console.log(loader.pid)
    if (error) {
        console.log(error.message);
    }
    console.log('Loaded: ', value);
});

Should I be trying to get it in a different way?

3 Answers
Related