#include #include #include #include #include #include int main(int argc, char *argv[]) { int fd; off_t size; char *mapping; unsigned r; unsigned i; if (argc != 2) { printf("Usage: %s \n", argv[0]); return EXIT_FAILURE; } fd = open(argv[1], O_RDONLY, 0); size = lseek(fd, 0, SEEK_END); mapping = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0); /* access (read) the file a couple of times*/ for (r = 0; r < 4; r++) { for (i = 0; i < size; i++) { char t = mapping[i]; } } munmap(mapping, size); close(fd); return EXIT_SUCCESS; }