Advertisement
teknoraver

overcommit

Nov 8th, 2017 (edited)
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.41 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <unistd.h>
  4.  
  5. int main(int argc, char *argv[])
  6. {
  7.     void *p;
  8.     intptr_t i;
  9.  
  10.     if (argc != 2) {
  11.         fprintf(stderr, "usage: %s <gigabytes>\n", *argv);
  12.         return 1;
  13.     }
  14.  
  15.     i = atol(argv[1]);
  16.  
  17.     /* allocate X GB */
  18.     p = sbrk(i * 1024 * 1024 * 1024);
  19.  
  20.     if ((intptr_t)p == -1) {
  21.         perror("sbrk");
  22.         return 1;
  23.     }
  24.  
  25.     /* sleep forever */
  26.     pause();
  27.  
  28.     return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement