Skip to content

Commit 36383b8

Browse files
authored
Fix spawned wmic processes not exiting when using pidusage in packaged apps (#186)
1 parent f5d46d1 commit 36383b8

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
### 4.0.1
2+
3+
- fix spawned wmic processes not exiting after wmic/gwmi detection in packaged apps, leading to infinite build up of "WMI Commandline Utility" processes and system instability
4+
15
### 4.0.0
26

37
- fix wmic removed on Windows 11 and add gwmi support

lib/stats.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,17 @@ function get (pids, options, callback) {
6161
}
6262
if (platform === 'win') {
6363
// TODO: use https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/where to avoid try/catch
64+
let child;
6465
try {
65-
spawn('wmic', function (err) {
66+
child = spawn('wmic', function (err) {
6667
if (err) throw new Error(err)
6768
})
6869
} catch (err) {
6970
fn = requireMap.gwmi()
71+
} finally {
72+
if (child) {
73+
child.kill()
74+
}
7075
}
7176
}
7277

0 commit comments

Comments
 (0)