Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sys/mman.h>
- #include <unistd.h>
- #include <time.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #define SIZE (1024 * 1024 * 100)
- #define ITERS (10000)
- int main(int argc, char** argv) {
- if (argc < 2) {
- fprintf(stderr, "Usage: %s file\n", argv[0]);
- return 1;
- }
- srand48(time(NULL));
- int fd = open(argv[1], O_CREAT | O_RDWR, 0600);
- char* arr = mmap(NULL, SIZE, PROT_WRITE | PROT_READ, MAP_SHARED, fd, 0);
- for (int i = 0; i < ITERS; i++) {
- fprintf(stderr, "Iteration %d\n", i);
- arr[lrand48() % SIZE] = (char) lrand48();
- fsync(fd);
- }
- munmap(arr, SIZE);
- close(fd);
- }
Advertisement
Add Comment
Please, Sign In to add comment