1

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?

Community
  • 1
  • 1
user3162878
  • 598
  • 3
  • 10
  • 25
  • Maybe you had a better chance on the [unix SE](http://unix.stackexchange.com). – peterh Sep 08 '15 at 01:52
  • unix SE. whats SE ?????? – user3162878 Sep 08 '15 at 04:57
  • stackexchange. This wonderful voting up - voting down - voting out in hird engine. – peterh Sep 08 '15 at 05:39
  • now since i have posted then now how shd i transfer to stackexchange? – user3162878 Sep 08 '15 at 09:55
  • Click the "edit" link, copy the text of your question, go to http://unix.stackexchange.com (similar site as this, from the same company, but with a little bit different outlook and rules), ask new question, paste into the textbox. But it looks your question finally wasn't closed (= moderated out), maybe it will even get an useful answer. – peterh Sep 08 '15 at 10:40

0 Answers0