systeminformation icon indicating copy to clipboard operation
systeminformation copied to clipboard

cpu returned by processes() may be negative on Windows

Open chend0316 opened this issue 2 years ago • 1 comments

When a very busy process exits, CPU may negative on Windows.

  1. run node ./test.js, this will call processes() every 1 second
  2. run node ./busy.js, this will take up one entire CPU core
  3. wait some time, my laptop has 16 CPU cores, so I need to wait at least 16 seconds
  4. Ctrl-C kill busy.js
  5. 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 avatar Jul 24 '21 09:07 chend0316

@chend0316 ... I made a comment to your pull request. Can you have a look on it?

sebhildebrandt avatar Aug 03 '21 14:08 sebhildebrandt