-
Notifications
You must be signed in to change notification settings - Fork 4
/
memory.c
41 lines (33 loc) · 863 Bytes
/
memory.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
31
32
33
34
35
36
37
38
39
40
41
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include <string.h>
int main( int argc, char *argv[] ) {
char *str,*p;
unsigned int secs = 30;
unsigned int timer;
int block = 500000;
if( argc == 2 ) {
block = strtol(argv[1], &p, 10);
}
str = NULL;
printf("PID = %d\n",getpid());
for(int i = 0 ; i < block; i++){
str = NULL;
str = (char *) malloc(1024);
if (str == NULL) {
printf("Fatal: failed to allocate bytes.\n");
abort();
}
strcpy(str, "simple_test");
}
printf("Reserving %d Kb of memory\n", block);
printf("Value of String = %s\n", str);
printf("Address = %u\n", str);
timer = time(0) + secs;
printf("Waiting for %d seconds\n", secs);
while (time(0) < timer);
free(str);
return(0);
}