summaryrefslogtreecommitdiff
path: root/src/hog.c
blob: d887f4df60b8690fe629b06b85c5b10489aa8071 (plain)
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
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
// Memory hog
int
main(int argc, const char *argv[])
{
	int j,k;
	char *p;
        int pid;
        int mallocsize;
        
        if (argc < 2) {
            fprintf(stderr,"Need malloc size parameter\n");
            exit(1);
        }
        mallocsize = atoi(argv[1]);
        for (k=0; k<5; k++) {
            p = malloc(mallocsize);
            if (p)
            for(j=0;j<mallocsize;j++)
                p[j] = j;
        pid = fork();
        
        if (pid)
        fprintf(stderr,"pid=%d\n",pid);
        }
        pid = getpid();
        for(j=0;j<mallocsize;j++)
                p[j] = pid;
        
        pause();
	// NOTREACHED
	return (0);
}