2022-10-06 22:07:48 +08:00
|
|
|
#include "processes.h"
|
|
|
|
|
|
2026-01-06 09:48:38 +08:00
|
|
|
#include "common/io.h"
|
2026-05-28 15:58:08 +08:00
|
|
|
#include "common/strutil.h"
|
2022-12-28 17:18:08 +08:00
|
|
|
|
2026-03-29 09:28:49 +08:00
|
|
|
const char* ffDetectProcesses(uint32_t* result) {
|
2023-10-11 21:09:43 +08:00
|
|
|
FF_AUTO_CLOSE_DIR DIR* dir = opendir("/proc");
|
2026-03-29 09:28:49 +08:00
|
|
|
if (dir == NULL) {
|
2023-10-11 21:09:43 +08:00
|
|
|
return "opendir(\"/proc\") failed";
|
2026-03-29 09:28:49 +08:00
|
|
|
}
|
2023-10-11 21:09:43 +08:00
|
|
|
|
|
|
|
|
uint32_t num = 0;
|
|
|
|
|
|
|
|
|
|
struct dirent* entry;
|
2026-03-29 09:28:49 +08:00
|
|
|
while ((entry = readdir(dir)) != NULL) {
|
2024-06-16 01:02:48 +08:00
|
|
|
if (
|
2026-03-29 09:28:49 +08:00
|
|
|
#ifdef _DIRENT_HAVE_D_TYPE
|
|
|
|
|
(entry->d_type == DT_DIR || entry->d_type == DT_UNKNOWN) &&
|
|
|
|
|
#endif
|
|
|
|
|
ffCharIsDigit(entry->d_name[0]))
|
2023-10-11 21:09:43 +08:00
|
|
|
++num;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*result = num;
|
2023-04-15 10:22:46 +08:00
|
|
|
|
|
|
|
|
return NULL;
|
2022-10-06 22:07:48 +08:00
|
|
|
}
|