/* * Memory tester by Quintela. */ #include #include #include #include #include #include #include #define FILENAME "/tmp/testing_file" /* Put here 2times your memory or less */ #define SIZE (128 * 1024 * 1024) void error_string(char *msg) { perror(msg); exit(EXIT_FAILURE); } int main(int argc, char * argv[]) { char *array; int i; int fd = open(FILENAME, O_RDWR | O_CREAT, 0666); if (fd == -1) error_string("Problems opening the file"); if (lseek(fd, SIZE, SEEK_SET) != SIZE) error_string("Problems doing the lseek"); if (write(fd,"\0",1) !=1) error_string("Problems writing"); array = mmap(0, SIZE, PROT_WRITE, MAP_SHARED,fd,0); if (array == MAP_FAILED) error_string("The mmap has failed"); for(i = 0; i < SIZE; i++) { array[i] = i; } msync(array, SIZE, MS_SYNC); close(fd); exit(EXIT_SUCCESS); }