Last active
February 17, 2017 04:05
-
-
Save pdu/58ca2c4a74be95b2043a6c9b950d6aa2 to your computer and use it in GitHub Desktop.
Eat memory program, have tested on Mac OSX
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 <stdlib.h> | |
#include <sys/mman.h> | |
#include <string.h> | |
#include <stdio.h> | |
int main(int argc, char** argv) { | |
size_t size = atoi(argv[1]) * 1024LL * 1024LL * 1024LL; | |
printf("%lu\n", size); | |
void *ptr = malloc(size); | |
memset(ptr, 0xff, size); | |
mlock(ptr, size); | |
int c; | |
scanf("%d", &c); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Compile:
$ g++ eat_memory.cpp -o eat_memory
Eat 10GB memory:
$ ./eat_memory 10