Created
April 19, 2017 16:23
-
-
Save ralphotowo/7897c8ce1e17c22dc17a1df1b4e645f4 to your computer and use it in GitHub Desktop.
C app (munch.c) to gobble up memory
This file contains hidden or 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 <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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Deactivate swap (unless you need it), compile with GCC and execute: