用随机数据填充内存 [英] fill memory with random data

查看:140
本文介绍了用随机数据填充内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在随机数据的linux机器上填充可用的RAM?



我这样问的原因:我在一个组中工作我们在Fortran中进行数值编程。有时候,人们会使用双精度实数工作,所以那些应该给出双精度结果的程序只能给出单精度。

如果我的理解是正确的,那么会看到随机的在这样的程序中单精度限制后的结果波动。也就是说,如果多次使用相同的输入运行相同的程序,则每次都会得到随机的不同结果。你看到的(随机部分)取决于机器可用RAM中的随机值。但在实践中,如果您在同一台机器上反复运行程序,则会重复使用相同的内存部分,这些内存中随机数据相同,每次都会产生相同的输出。

我的想法是,如果您可以用随机数据覆盖内存,您实际上会看到程序输出中的随机波动。这会让它更容易找到这些错误。



这个想法是否重要?如果不是,我该如何填充内存?我可以将/ dev / random插入内存或其他内容吗?

解决方案

Linux为您提供 / proc / pid / maps / proc / pid / mem ,为了您的乐趣。在那里写作时你必须格外小心。另外,请记住每个进程可用的唯一内存段是它自己的,因此您可能需要执行一些附加和代码修补以获得所需的位置。好运,反正。 :)

编辑:它比代码审计还要复杂得多 - 它也更有可能揭示问题的实际来源。


Is there a way to fill the free RAM on a linux machine with random data?

The reason I'm asking this: I'm working in a group where we do numerical programming in Fortran. Sometimes, people mess up working with double precision reals, so that programs that should give double precision results only give single precision.

If my understanding is correct, one would see random fluctuations of the result after the single precision limit in such a program. That is, if you run the same program with the same input several times, you get randomly different result each time. What you see (the random part) depends on the random values in the free RAM of the machine. But in practice, if you run the program repeatedly on the same machine, the same parts of memory tend to be used repeatedly, which have the same random data in them, leading the same output every time.

My idea is that if you could overwrite the memory with random data, you would actually see the random fluctuations in your program output. That would make it a lot easier to find these bugs.

Is this idea whack, or if not, how do I fill the memory? Can I pipe /dev/random into the RAM, or something?

解决方案

Linux provides you with /proc/pid/maps and /proc/pid/mem, for your own pleasure. Of course you have to be extra careful when writing there. Also, keep in mind the only memory segment available to each process is its own, so you'll probably have to do some attaching and code patching to get where you want. Good luck, anyways. :)

edit: It's still quite a few times more complicated than a code audit - which also has greater chances to reveal the actual source of the problem.

这篇关于用随机数据填充内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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