-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmemTest.c
30 lines (24 loc) · 929 Bytes
/
memTest.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/**********************************************************************************
* This program is based directly on munch.c provided by linuxatemyram.com *
* I claim no ownership for the code and have modified it from the original *
* version. Use "gcc memTest.c -o memtest" to compile. This program just uses up *
* RAM until the linux kernel desides to envoke OOM killer on it. *
* *******************************************************************************/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.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(50*1024*1024)) != NULL && mb != max) {
memset(buffer, 0, 50*1024*1024);
mb++;
printf("Allocated memory %d times.\n", mb);
sleep(5);
}
return 0;
}