I am trying to write a code in Linux C. Basically I am trying to draw a statistic that should show like: pid, number of process, page fault(major/minor) and total number of page faults.
val, pid, pagefault, number of processes, total number of pages faults(Majpr+Minor)
1 127 major 1 2323
for an idea I took the code solution from https://unix.stackexchange.com/questions/188170/generate-major-page-faults and its code:
#include <fcntl.h>
#include <stdio.h>
#include <sys/mman.h>
#include <sys/stat.h>
int main(int argc, char ** argv) {
int fd = open(argv[1], O_RDONLY);
struct stat stats;
fstat(fd, &stats);
posix_fadvise(fd, 0, stats.st_size, POSIX_FADV_DONTNEED);
char * map = (char *) mmap(NULL, stats.st_size, PROT_READ, MAP_SHARED, fd, 0);
if (map == MAP_FAILED) {
perror("Failed to mmap");
return 1;
}
int result = 0;
int i;
for (i = 0; i < stats.st_size; i++) {
result += map[i];
}
munmap(map, stats.st_size);
return result;
}
this code does but giving too much things. I also saw this link sol: Measure page faults from a c program but failed to make my way that how shd i get the page faults(Major/Minor). Anyone who can tell me how to get major and minor faults?