#include #include #include int main(int argc, char *argv[]) { int mbs_to_hog = 0; int i, j; char *buf; if (argc < 2) { printf("specify amount of memory to hog in MB"); exit(1); } mbs_to_hog = atoi(argv[1]); printf("hogging %d MB:", mbs_to_hog); fflush(stdout); for (i = 0; i < mbs_to_hog; ++i) { buf = malloc(1000*1000); if (!buf) { printf("ran out of memory"); exit(1); } for (j = 0; j < 1000*1000; ++j) buf[j] = j; if ((i + 1) % 20 == 0) { printf(" %d", (i + 1)); fflush(stdout); } } if (i % 20 != 0) { printf(" %d", i); fflush(stdout); } printf("\n"); sleep(60); return 0; }