The ProcsTotal in the MiscStat structure was very inaccurate. It was reading a value which is the total number of kernel scheduling entities. This includes both processes and threads significantly overcounting.
This instead uses an existing method already in common to count the number of processes via the /proc filesystem where any directory is a number. This should still be a single syscall to read that directory entry.
I don't see any existing automated test with this functionality so I did not add any but I did do my own manual testing by writing the following program:
The
ProcsTotal
in theMiscStat
structure was very inaccurate. It was reading a value which is the total number of kernel scheduling entities. This includes both processes and threads significantly overcounting.This instead uses an existing method already in common to count the number of processes via the /proc filesystem where any directory is a number. This should still be a single syscall to read that directory entry.
I don't see any existing automated test with this functionality so I did not add any but I did do my own manual testing by writing the following program:
With the previous code it was returning a value of over 1200. After the change the count was around 320 and matched
ps -A | wc -l
.This fixes #1606.