Skip to content

Commit

Permalink
Use tree-kill instead of custom function to try terminating all proce…
Browse files Browse the repository at this point in the history
…ss without issues
  • Loading branch information
Elanis committed Jul 31, 2023
1 parent 205fd0c commit 9468bca
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 29 deletions.
16 changes: 15 additions & 1 deletion runner/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion runner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"node-fetch": "^3.3.1",
"pidtree": "^0.6.0",
"pidusage": "^3.0.2",
"systeminformation": "^5.17.16"
"systeminformation": "^5.17.16",
"tree-kill": "^1.2.2"
}
}
30 changes: 3 additions & 27 deletions runner/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import pidusage from 'pidusage';
import pidtree from 'pidtree';
import os from 'os';
import systeminformation from 'systeminformation';
import kill from 'tree-kill';

import {
ITERATIONS_PER_PROCESS,
Expand Down Expand Up @@ -81,31 +82,6 @@ async function execBuildProcess(processPath, processExe) {
});
}

export function killAll(pid, signal='SIGTERM'){
if(process.platform == "win32"){
exec(`taskkill /PID ${pid} /T /F`, (error, stdout, stderr)=>{
console.log("taskkill stdout: " + stdout)
console.log("taskkill stderr: " + stderr)
if(error){
console.log("error: " + error.message)
}
})
}

// see https://nodejs.org/api/child_process.html#child_process_options_detached
// If pid is less than -1, then sig is sent to every process in the process group whose ID is -pid.
try {
try {
process.kill(-pid, signal);
} catch(e) {
console.error(e);
process.kill(pid, signal);
}
} catch(e) {
console.error(e);
}
}

async function sleep(seconds) {
return (await new Promise((resolve, _reject) => {
setTimeout(resolve, seconds * 1000);
Expand Down Expand Up @@ -285,10 +261,10 @@ async function getMemoryUsageHistoryOfProcess(processPath, processExe, timeout=D
clearInterval(interval);

if(childProcess.exitCode === null && !done) {
killAll(childProcess.pid);
kill(childProcess.pid);
} else {
try {
killAll(childProcess.pid);
kill(childProcess.pid);
} catch {}
}
}
Expand Down

0 comments on commit 9468bca

Please sign in to comment.