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
#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 <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[4096];

    while(1) { 
      unsigned off = (random() % 10000000) & 0xffff1000;
      lseek(fd, off, SEEK_SET);
      read(fd, buf, 4096);
      Count += 1;
    }
  }

  exit(0);

}