diff --git a/api/package-lock.json b/api/package-lock.json index b462747..c066efc 100644 --- a/api/package-lock.json +++ b/api/package-lock.json @@ -16,7 +16,6 @@ "logplease": "^1.2.15", "nocamel": "HexF/nocamel#patch-1", "node-fetch": "^2.6.1", - "ps-list": "^7.2.0", "semver": "^7.3.4", "uuid": "^8.3.2", "waitpid": "git+https://github.com/HexF/node-waitpid.git" @@ -404,14 +403,6 @@ "node": ">= 0.10" } }, - "node_modules/ps-list": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/ps-list/-/ps-list-7.2.0.tgz", - "integrity": "sha512-v4Bl6I3f2kJfr5o80ShABNHAokIgY+wFDTQfE+X3zWYgSGQOCBeYptLZUpoOALBqO5EawmDN/tjTldJesd0ujQ==", - "engines": { - "node": ">=10" - } - }, "node_modules/qs": { "version": "6.7.0", "resolved": "https://registry.npmjs.org/qs/-/qs-6.7.0.tgz", @@ -873,11 +864,6 @@ "ipaddr.js": "1.9.1" } }, - "ps-list": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/ps-list/-/ps-list-7.2.0.tgz", - "integrity": "sha512-v4Bl6I3f2kJfr5o80ShABNHAokIgY+wFDTQfE+X3zWYgSGQOCBeYptLZUpoOALBqO5EawmDN/tjTldJesd0ujQ==" - }, "qs": { "version": "6.7.0", "resolved": "https://registry.npmjs.org/qs/-/qs-6.7.0.tgz", diff --git a/api/package.json b/api/package.json index 3517fd3..cefd900 100644 --- a/api/package.json +++ b/api/package.json @@ -11,7 +11,6 @@ "logplease": "^1.2.15", "nocamel": "HexF/nocamel#patch-1", "node-fetch": "^2.6.1", - "ps-list": "^7.2.0", "semver": "^7.3.4", "uuid": "^8.3.2", "waitpid": "git+https://github.com/HexF/node-waitpid.git" diff --git a/api/src/job.js b/api/src/job.js index fcbfb23..9484974 100644 --- a/api/src/job.js +++ b/api/src/job.js @@ -5,7 +5,6 @@ const path = require('path'); const config = require('./config'); const globals = require('./globals'); const fs = require('fs/promises'); -const ps_list = require('ps-list'); const wait_pid = require('waitpid'); const job_states = { @@ -194,8 +193,25 @@ class Job { async cleanup_processes(){ let processes = [1]; while(processes.length > 0){ - processes = await ps_list(); - processes = processes.filter(proc => proc.uid == this.uid); + processes = await new Promise((resolve, reject) => cp.execFile('ps', ['awwxo', 'pid,ruid'], function(err, stdout) { + if(err === null){ + const lines = stdout.split('\n').slice(1); //Remove header with slice + const procs = lines.map(line => { + const [pid, ruid] = line + .trim() + .split(/\s+/) + .map(n => parseInt(n)); + + return { pid, ruid } + }) + resolve(procs) + } + else{ + reject(error) + } + })); + + processes = processes.filter(proc => proc.ruid == this.uid); for(const proc of processes){ // First stop the processes, but keep their resources allocated so they cant re-fork