From de93441b5e61b7aa3a654ef9d871e2f3c526af31 Mon Sep 17 00:00:00 2001 From: Mihail Bodrov Date: Fri, 2 Feb 2018 03:06:13 +0300 Subject: [PATCH] Optimize process kill by pid --- src/buffered-process.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/buffered-process.js b/src/buffered-process.js index 0a01671fa..c82c78fac 100644 --- a/src/buffered-process.js +++ b/src/buffered-process.js @@ -189,12 +189,12 @@ class BufferedProcess { output += data }) wmicProcess.stdout.on('close', () => { - const pidsToKill = output.split(/\s+/) - .filter((pid) => /^\d+$/.test(pid)) - .map((pid) => parseInt(pid)) - .filter((pid) => pid !== parentPid && pid > 0 && pid < Infinity) + for (let pid of output.split(/\s+/)) { + if (!/^\d{1,10}$/.test(pid)) continue + pid = parseInt(pid, 10) + + if (!pid || pid === parentPid) continue - for (let pid of pidsToKill) { try { process.kill(pid) } catch (error) {}