+#include <sys/types.h>
+#include <dirent.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
return;
}
+
+static int get_next_pid(void)
+{
+ static DIR *dir = NULL;
+ struct dirent *dirent;
+ int error;
+
+ if (!dir) {
+ dir = opendir("/proc");
+ if (!dir) {
+ error = errno;
+ printf("Failed to open /proc directory: %s\n",
+ strerror(error));
+ return -1;
+ }
+ }
+
+restart:
+ dirent = readdir(dir);
+ if (!dirent) {
+ if (errno == 0) {
+ closedir(dir);
+ dir = NULL;
+ return 0;
+ }
+ error = errno;
+ printf("Failed to read directory: %s\n", strerror(error));
+ return -1;
+ }
+
+ printf("%s\n", dirent->d_name);
+ if (dirent->d_name[0] < '0' || dirent->d_name[0] > '9')
+ goto restart;
+
+ return atoi(dirent->d_name);
+}
+
+void scan_all_pids(struct pageframe *pf)
+{
+ int pid;
+ while(1) {
+ pid = get_next_pid();
+ if (pid <= 0)
+ break;
+ read_pageframe(pid, pf);
+ }
+}
#include "pagemap.h"
void read_pageframe(int pid, struct pageframe *pageframe);
+void scan_all_pids(struct pageframe *pf);
#endif