Skip to content

Instantly share code, notes, and snippets.

@ajkr ajkr/mlock.c
Created Aug 7, 2019

Embed
What would you like to do?
#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
You can’t perform that action at this time.