-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmalloc-thread.c
More file actions
49 lines (38 loc) · 963 Bytes
/
malloc-thread.c
File metadata and controls
49 lines (38 loc) · 963 Bytes
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
42
43
44
45
46
47
48
49
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <pthread.h>
#include <unistd.h>
#define GB 1024*1024*1024
void *simplemalloc(void *arg)
{
char *p;
p = (char *)malloc(GB*sizeof(char));
memset(p, 0, GB*sizeof(char));
pthread_exit(p);
}
int main(int argc, char *argv[])
{
int i, thread_count=2, second=0;
pthread_t thread[thread_count];
void *status[thread_count];
char cmd[256];
sprintf(cmd, "grep VmSize /proc/%d/status 1>&2", getpid());
fprintf(stderr, "Pre\n");
system(cmd);
fprintf(stderr, "Exec\n");
for(i=0; i<thread_count; i++)
{
pthread_create(&thread[i], NULL, simplemalloc, (void *)NULL);
system(cmd);
}
for(i=0; i<thread_count; i++)
pthread_join(thread[i], &status[i]);
sleep(second);
for(i=0; i<thread_count; i++)
free(status[i]);
fprintf(stderr, "Post\n");
system(cmd);
return 0;
}