Processes (Linux): fix implementation

`sysinfo.procs` reports number of all running threads, instead of processes
This commit is contained in:
李通洲
2023-10-11 21:09:43 +08:00
parent 582788645d
commit ebab281471
2 changed files with 18 additions and 5 deletions
+1
View File
@@ -15,6 +15,7 @@ Bugfixes:
* Fix possible crashes caused by uninitialized strings (Users, Windows)
* Improve support of `--help *-format` and several bugs are found and fixed
* Don't incorrectly print `No active sound devices found` when using a non-controllable sound device (Sound, macOS)
* Fix implementation processes counting (Processes, Linux)
Logo:
* Add Chimera Linux
+17 -5
View File
@@ -1,13 +1,25 @@
#include "processes.h"
#include <sys/sysinfo.h>
#include "common/io/io.h"
#include <ctype.h>
const char* ffDetectProcesses(uint32_t* result)
{
struct sysinfo info;
if(sysinfo(&info) != 0)
return "sysinfo() failed";
FF_AUTO_CLOSE_DIR DIR* dir = opendir("/proc");
if(dir == NULL)
return "opendir(\"/proc\") failed";
uint32_t num = 0;
struct dirent* entry;
while ((entry = readdir(dir)) != NULL)
{
if (entry->d_type == DT_DIR && isdigit(entry->d_name[0]))
++num;
}
*result = num;
*result = (uint32_t) info.procs;
return NULL;
}