SHARE
TWEET

Untitled

a guest Apr 24th, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. // Allocate memory forever (mostly)
  3. // The OS should kill the process
  4. //
  5.  
  6. #include <stdlib.h>
  7. #include <stdio.h>
  8. #include <string.h>
  9.  
  10. int main(int argc, char** argv) {
  11.     const int mb_size = 50 ;
  12.     char* buffer;
  13.  
  14.     while (1) {
  15.       buffer=malloc(1024*1024*mb_size);
  16.       mb++;
  17.       if (buffer == NULL) {
  18.         printf("Unable to allocate buffer");
  19.       } else {
  20.          memset(buffer, 0, 1024*1024*mb_size);
  21.       }
  22.       printf("Allocated %d MB\n", mb*mb_size);
  23.       // Yield process so that UIs update and it can be interrupted
  24.       usleep(50000);
  25.     }
  26.  
  27.  }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top