C Program on Linux to exhaust memory

前端 未结 10 707
孤独总比滥情好
孤独总比滥情好 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:23

    Linux "over commits" memory. This means that physical memory is only given to a process when the process first tries to access it, not when the malloc is first executed. To disable this behavior, do the following (as root):

    echo 2 > /proc/sys/vm/overcommit_memory
    

    Then try running your program.

提交回复
热议问题