mirror of
https://github.com/engineer-man/piston.git
synced 2025-04-20 20:16:26 +02:00
zombie process handler
This commit is contained in:
parent
347f2d56d7
commit
3673b4e403
4 changed files with 32 additions and 733 deletions
|
@ -6,7 +6,7 @@ const config = require('./config');
|
|||
const globals = require('./globals');
|
||||
const fs = require('fs/promises');
|
||||
const ps_list = require('ps-list');
|
||||
const wait_pid = require('waitpid2');
|
||||
const wait_pid = require('waitpid');
|
||||
|
||||
const job_states = {
|
||||
READY: Symbol('Ready to be primed'),
|
||||
|
@ -185,18 +185,17 @@ class Job {
|
|||
async cleanup() {
|
||||
logger.info(`Cleaning up job uuid=${this.uuid}`);
|
||||
await fs.rm(this.dir, { recursive: true, force: true });
|
||||
let processes = [1]
|
||||
while(processes.length > 0){
|
||||
|
||||
let processes = await ps_list();
|
||||
processes.filter(proc => proc.uid == this.uid);
|
||||
processes = await ps_list();
|
||||
processes = processes.filter(proc => proc.uid == this.uid);
|
||||
|
||||
await Promise.all(
|
||||
processes.map(
|
||||
async proc => {
|
||||
process.kill(proc.pid, 'SIGKILL');
|
||||
wait_pid(proc.pid, wait_pid.WNOHANG); //Free zombie state process
|
||||
}
|
||||
)
|
||||
);
|
||||
for(const proc of processes){
|
||||
process.kill(proc.pid, 'SIGKILL');
|
||||
wait_pid(proc.pid);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue