1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <sys/mman.h>
#include <time.h>
#include <netdb.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <errno.h>
#include <assert.h>

int Count = 0;

static void
_alrm(int sig) { 
	printf("%d\n", Count);
	exit(0);	
}

int
main(int argc, char **argv) {
	int fd = 0;

	signal(SIGALRM, _alrm);
	alarm(10);
	srandom(time(NULL));

	if((fd = open("test.raw", O_RDONLY)) != -1) { 
		u_char *buf = NULL;
		int acc = 0;

		if((buf = mmap(NULL, 10000000, PROT_READ, MAP_PRIVATE, fd, 0)) != -1) { 
			while(1) { 
	                        unsigned off = (random() % 10000000) & 0xffff1000;
				int i = 0; 

				for(i = 0; i < 4000; i += 4) 
					acc += buf[off + i];

				Count += 1;
			}
		} else {
			perror("mmap");
		}
	}

	exit(0);

}