我正在尝试使用Linux上的C程序读取大小为1kB到1GB的文件时的页面错误数。我正在使用下面提到的步骤:
dd if = / dev / zero of = file1.txt count = 1024 bs = 1024
#sync; echo 1>的/ proc / SYS / VM / drop_caches
#include <sys/time.h> #include <sys/resource.h> #include <unistd.h> #include <stdio.h> int main() { struct rusage usage; //struct timeval start, end; long int st,ed; int i, j, k = 0; getrusage(RUSAGE_SELF, &usage); st = usage.ru_majflt; FILE *fp; int c; int n = 0; fp = fopen("file6.txt","r"); if(fp == NULL) { perror("Error in opening file"); return(-1); } while(!feof(fp)) { c = fgetc(fp); } fclose(fp); getrusage(RUSAGE_SELF, &usage); ed = usage.ru_majflt; printf("Started at: %ld \n", st); printf("Ended at: %ld \n", ed); return 0; }
当我运行代码时,我得到了意外的输出。
Started at: 0
Ended at: 0
我哪里出错?