Created
August 7, 2019 20:07
-
-
Save ajkr/f7501a1177647e9a45cb636002c76e39 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <sys/mman.h> | |
int main(int argc, char** argv) { | |
if (argc != 3) { | |
fprintf(stderr, "usage: %s <num blocks> <block size>\n", argv[0]); | |
exit(1); | |
} | |
int num_blocks = atoi(argv[1]); | |
int block_size = atoi(argv[2]); | |
for (int i = 0; i < num_blocks; ++i) { | |
void* alloc = malloc(block_size); | |
if (alloc == NULL) { | |
fprintf(stderr, "malloc failed\n"); | |
exit(1); | |
} | |
int ret = mlock(alloc, block_size); | |
if (ret == -1) { | |
perror("mlock"); | |
exit(1); | |
} | |
} | |
getchar(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment