#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
int main()
{
const size_t NUM = 500 * 1000 * 1000;
while(1) {
int *a = (int *)malloc( NUM * sizeof(int) );
if (!a) printf( "Tsar' - shkolnik\n" );
sleep( 1 );
}
return 0;
}
#> uname -a
Linux user-VirtualBox 3.8.0-35-generic #50-Ubuntu SMP Tue Dec 3 01:25:33 UTC 2013 i686 i686 i686 GNU/Linux
#> free -m
total used free shared buffers cached
Mem: 1002 594 408 0 9 108
-/+ buffers/cache: 476 526
Swap: 1021 129 892
#> sysctl -a|grep overcommit
vm.nr_overcommit_hugepages = 0
vm.overcommit_memory = 0
vm.overcommit_ratio = 50
#> gcc malloc_test.cpp -o m && ./m
Tsar' - shkolnik
Tsar' - shkolnik
Tsar' - shkolnik
^C