Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement