/* * eatmem.c -- allocate a junk of memory and make it dirty * Copyright Harald Koenig 1994 * * Permission is hereby granted to copy, modify and redistribute this code * in terms of the GNU Library General Public License, Version 2 or later, * at your option. * * to compile use * cc -O2 -Wall -fomit-frame-pointer -s -o eatmem eatmem.c */ #include #include #include #include #include int main(int argc, char *argv[]) { int i; char *b=NULL,*pb; int n=(-1); int err=0, exit_flag=0, loop_flag=0; if (argc >= 2) { n = atoi(argv[1]); if (argc == 3) { if (!strcmp(argv[2],"pause")) exit_flag = 0; else if (!strcmp(argv[2],"exit" )) exit_flag = 1; else if (!strcmp(argv[2],"loop" )) loop_flag = 1; else err=1; } else if (argc > 3) err=1; } if (n<=0 || err) { fprintf(stderr,"usage: eatmem size_in_kb [ pause | exit | loop ]\n"); exit(1); } b = malloc(n*1024); if (b == NULL) { fprintf(stderr,"malloc failed.\n"); exit(1); } do { pb = b; for (i=0; i