Skip to content

Commit ebab281

Browse files
committed
Processes (Linux): fix implementation
`sysinfo.procs` reports number of all running threads, instead of processes
1 parent 5827886 commit ebab281

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Bugfixes:
1515
* Fix possible crashes caused by uninitialized strings (Users, Windows)
1616
* Improve support of `--help *-format` and several bugs are found and fixed
1717
* Don't incorrectly print `No active sound devices found` when using a non-controllable sound device (Sound, macOS)
18+
* Fix implementation processes counting (Processes, Linux)
1819

1920
Logo:
2021
* Add Chimera Linux
Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
11
#include "processes.h"
22

3-
#include <sys/sysinfo.h>
3+
#include "common/io/io.h"
4+
5+
#include <ctype.h>
46

57
const char* ffDetectProcesses(uint32_t* result)
68
{
7-
struct sysinfo info;
8-
if(sysinfo(&info) != 0)
9-
return "sysinfo() failed";
9+
FF_AUTO_CLOSE_DIR DIR* dir = opendir("/proc");
10+
if(dir == NULL)
11+
return "opendir(\"/proc\") failed";
12+
13+
uint32_t num = 0;
14+
15+
struct dirent* entry;
16+
while ((entry = readdir(dir)) != NULL)
17+
{
18+
if (entry->d_type == DT_DIR && isdigit(entry->d_name[0]))
19+
++num;
20+
}
21+
22+
*result = num;
1023

11-
*result = (uint32_t) info.procs;
1224
return NULL;
1325
}

0 commit comments

Comments
 (0)