Skip to content

Instantly share code, notes, and snippets.

@ralphotowo
Created April 19, 2017 16:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ralphotowo/7897c8ce1e17c22dc17a1df1b4e645f4 to your computer and use it in GitHub Desktop.
Save ralphotowo/7897c8ce1e17c22dc17a1df1b4e645f4 to your computer and use it in GitHub Desktop.
C app (munch.c) to gobble up memory
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main(int argc, char** argv) {
int max = -1;
int mb = 0;
char* buffer;
if(argc > 1)
max = atoi(argv[1]);
while((buffer=malloc(1024*1024)) != NULL && mb != max) {
memset(buffer, 0, 1024*1024);
mb++;
printf("Allocated %d MB\n", mb);
}
return 0;
}
@ralphotowo
Copy link
Author

Deactivate swap (unless you need it), compile with GCC and execute:

$ sudo swapoff -a
$ free -m
$ gcc munch.c -o munch
$ ./munch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment