systeminformation
systeminformation copied to clipboard
cpu returned by processes() may be negative on Windows
When a very busy process exits, CPU may negative on Windows.
- run
node ./test.js
, this will callprocesses()
every 1 second - run
node ./busy.js
, this will take up one entire CPU core - wait some time, my laptop has 16 CPU cores, so I need to wait at least 16 seconds
- Ctrl-C kill busy.js
- test.js will print negative CPU value
busy.js:
while (true) {
for (let i = 0; i < 100000000; i++) {
}
}
test.js
const { processes } = require('systeminformation')
setInterval(() => {
const curPid = process.pid
processes().then((result) => {
const processInfo = result.list.filter(({pid}) => pid === curPid)[0]
console.log(processInfo.cpu)
})
}, 1000)
@chend0316 ... I made a comment to your pull request. Can you have a look on it?