如何强制程序出现内存不足? [英] How do I force a program to appear to run out of memory?

查看:99
本文介绍了如何强制程序出现内存不足?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C / C ++程序,当内存不足时可能挂起。我们通过同时运行多个副本来发现这一点。我想调试程序,而不会在开发机器上完全破坏性能。有没有办法限制可用的内存,以便在请求500K的内存之后,新的或malloc将返回NULL指针?

I have a C/C++ program that might be hanging when it runs out of memory. We discovered this by running many copies at the same time. I want to debug the program without completely destroying performance on the development machine. Is there a way to limit the memory available so that a new or malloc will return a NULL pointer after, say, 500K of memory has been requested?

推荐答案

尝试在头上转动问题,并询问如何限制操作系统允许您的进程使用的内存量。

Try turning the question on its head and asking how to limit the amount of memory an OS will allow your process to use.

尝试查看< a href =http://ss64.com/bash/ulimit.html =noreferrer> http://ss64.com/bash/ulimit.html

尝试说:
ulimit -v

Try say: ulimit -v

这是另一个有点旧的链接,但是再多一点:$ b​​ $ b http://www.network-theory.co.uk/docs/ gccintro / gccintro_77.html

Here is another link that's a little old but gives a little more back ground: http://www.network-theory.co.uk/docs/gccintro/gccintro_77.html

这篇关于如何强制程序出现内存不足?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆