Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jul 28th, 2013  |  syntax: C  |  size: 0.76 KB  |  views: 32  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <sys/mman.h>
  5. #include <string.h>
  6. #include <errno.h>
  7.  
  8. int main (int argc, char *argv[])
  9. {
  10.     int size = 1024 * 1024 * 100;
  11.    
  12.     for (int i = 0; i < 10000000; ++i) {
  13.         void* mem = mmap(0, size, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_ANON, 0, 0);
  14.         if (mem == MAP_FAILED) {
  15.             fprintf(stderr, "#%d, map failed (%s)\n", i, strerror(errno));
  16.             sleep(5);
  17.             exit(1);
  18.         }
  19.         // int* ptr = (int*) mem;
  20.         // ++(*ptr);
  21.         if (i % 100000 == 0)
  22.             printf("#%d, Allocated %d bytes at %p\n", i, size, mem);
  23.     }
  24.     printf("Sleeping...");
  25.     fflush(stdout);
  26.     sleep(30);
  27.     printf(" Exiting...\n");
  28.     return 0;
  29. }
clone this paste RAW Paste Data