diff --git a/linux/cpu_memory_by_process.c b/linux/cpu_memory_by_process.c index 88ee631..6b27d26 100644 --- a/linux/cpu_memory_by_process.c +++ b/linux/cpu_memory_by_process.c @@ -197,7 +197,7 @@ uint64 ReadTotalCPUUsage() void ReadCPUMemoryUsage(int sample) { FILE *fpstat; - struct dirent *ent, dbuf; + struct dirent *ent; char file_name[MAXPGPATH]; long utime_ticks, stime_ticks; char process_name[MAXPGPATH] = {0}; @@ -227,7 +227,7 @@ void ReadCPUMemoryUsage(int sample) return; } - while (readdir_r(dirp, &dbuf, &ent) == 0) + while ((ent = readdir(dirp)) != NULL) { memset(file_name, 0x00, MAXPGPATH); diff --git a/linux/system_stats_utils.c b/linux/system_stats_utils.c index 2be6e64..9703d3c 100644 --- a/linux/system_stats_utils.c +++ b/linux/system_stats_utils.c @@ -138,7 +138,7 @@ bool read_process_status(int *active_processes, int *running_processes, { FILE *fpstat; DIR *dirp; - struct dirent *ent, dbuf; + struct dirent *ent; char file_name[MIN_BUFFER_SIZE]; char process_type; unsigned int running_threads; @@ -156,14 +156,11 @@ bool read_process_status(int *active_processes, int *running_processes, } /* Read the proc directory for process status */ - while (readdir_r(dirp, &dbuf, &ent) == 0) + while ((ent = readdir(dirp)) != NULL) { memset(file_name, 0x00, MIN_BUFFER_SIZE); process_type = '\0'; - if (!ent) - break; - /* Iterate only digit as name because it is process id */ if (!isdigit(*ent->d_name)) continue; @@ -182,7 +179,7 @@ bool read_process_status(int *active_processes, int *running_processes, if (process_type == 'R') running_pro++; - else if(process_type == 'S' || process_type == 'D') + else if (process_type == 'S' || process_type == 'D') sleeping_pro++; else if (process_type == 'T') stopped_pro++; @@ -209,6 +206,7 @@ bool read_process_status(int *active_processes, int *running_processes, return true; } + void ReadFileContent(const char *file_name, uint64 *data) { FILE *fp = NULL;