The code below, allocates 10 MB per allocation, do monitor the swap.[1]
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main(int argc, char** argv) {
int max = -1, mb = 0;
char* buffer;
if(argc > 1)
max = atoi(argv[1]);
else {
printf("\nmeater <size in MB> eg: meater 2048\n");
exit(0);
}
printf("\n[INFO] attempting to allocate %d MB @ 10 MB\n", max);
while((buffer=malloc(10*1024*1024)) != NULL && mb != max/10) {
memset(buffer, 0, 10*1024*1024);
mb++;
printf("[INFO] allocated %d MB\n", mb*10);
sleep(1);
}
printf("[INFO] meater done eating, yummy..!\n");
return 0;
}
No comments :
Post a Comment