Electron and node on windows, kill spawned process

I start the background process (on windows) from the main electron, something like this:

app_exe = require("child_process").spawn(
  "app.exe" ,
  [ "--params", ... ],
  { stdio: "ignore" }
);

this works fine, I can see it from Process Explorer: enter image description here

but I can’t kill the process when the electron is closed ( .on("closed")or on("window-all-closed"))

I tried child.kill([signal]), but also destroying the trees or taskkill to no avail: only the first process (6036 from the example) was killed, the second (5760) remains obsolete.

also exec taskkill /F /T /PIDdoesn't kill him.

the only way to kill is exec taskkill /F /IM app.exe /T, but this way I cannot start two instances of the electronic application.

i'm missing something obvious in process management on windows

+8
2

, / . :

// Workaround to close all processes / sub-processes after closing the app
electron.app.once('window-all-closed', electron.app.quit);
electron.app.once('before-quit', () => {
    window.removeAllListeners('close');
});

, , .

0

Windows 7. , .

, PID SIGTERM, , . , , Electron, , , PID , find-process npm. , PID, , .

const proc = cp.spawn("app.exe");

app.on("window-all-closed", async () => {
    const list = await require("find-process")("pid", proc.pid);
    app.quit();
    if (list[0] && list[0].name.toLowerCase() === "app.exe")
        process.kill(proc.pid);
});

, Electron ( ), .

, , , . , .

, , .

0

Source: https://habr.com/ru/post/1669284/


All Articles