return parse_pid(dir);
}
-static int get_next_pid(void)
+static int get_next_pid(DIR **dir)
{
- static DIR *dir = NULL;
int error;
- if (!dir) {
- dir = opendir("/proc");
+ if (!*dir) {
+ *dir = opendir("/proc");
if (!dir) {
error = errno;
printf("Failed to open /proc directory: %s\n",
}
}
- return parse_pid(&dir);
+ return parse_pid(dir);
}
static void read_pageframe_with_threads(int pid,
void scan_all_pids(struct pageframe *pf, struct process **process_list,
struct parse_opts *opts)
{
+ DIR *dir = NULL;
int pid;
if (opts->parse_mask & PARSE_PID)
read_pageframe_with_threads(opts->pid, pf, process_list, opts);
while(1) {
- pid = get_next_pid();
+ pid = get_next_pid(&dir);
if (pid <= 0)
break;
read_pageframe_with_threads(pid, pf, process_list, opts);