我正在编写一个程序来泄露内存(主内存),以测试系统在低系统内存和交换内存下的行为。我们使用以下循环定期运行并泄漏内存。
main(int argc, char* argv[] )
{
int arg_mem = argv[1];
while(1)
{
u_int_ptr =(unsigned int*) malloc(arg_mem * 1024 * 1024);
if( u_int_ptr == NULL )
printf("\n leakyapp Daemon FAILED due to insufficient available memory....");
sleep( arg_time );
}
}
循环运行一段时间后,打印消息“由于可用内存不足,leakyapp守护进程失败...”。但是当我运行命令“free”时,我可以看到运行此程序对主内存或交换空间没有影响。
我做错了什么吗?