DF-2701 / hog.c
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #define CHUNK (16UL * 1024 * 1024) /* 16MB chunks */ #define NCHUNK 320 /* ~5GB total, forces swap on 4GB box */ int main(void) { char *p[NCHUNK]; for (unsigned long i = 0; i < NCHUNK; i++) { p[i] = malloc(CHUNK); if (!p[i]) { fprintf(stderr, "oom at %lu\n", i); break; } memset(p[i], (int)(i & 0xff), CHUNK); if ((i & 15) == 0) { fprintf(stderr, "touched %lu MB\n", (i+1) * 16); usleep(20000); } } /* keep it resident-ish busy then exit */ sleep(2); return 0; } |