C Program on Linux to exhaust memory

前端 未结 10 704
孤独总比滥情好
孤独总比滥情好 2020-12-24 03:06

I would like to write a program to consume all the memory available to understand the outcome. I\'ve heard that linux starts killing the processes once it is unable to alloc

10条回答
  •  佛祖请我去吃肉
    2020-12-24 03:28

    Have a look at this program. When there is no longer enough memory malloc starts returning 0

    #include 
    #include 
    
    int main()
    {
      while(1)
      {
        printf("malloc %d\n", (int)malloc(1024*1024));
      }
      return 0;
    }
    

提交回复
热议问题