我正在设置警报。有人能建议一种简单的方法来强制在 vanilla ubuntu 上出现内存不足的情况吗?
答案1
如果您有 root 权限,是的。
sudo mkdir /media/RAM # Let's make a mount point
sudo mount /dev/ram /media/RAM # Let's tell the OS to use RAM as storage
cd /media/RAM # Let's go to the RAM directory
i=0 # Let's get an iteration counter
while true # Let's do something forever (or at least as long as we can)
do # Do something
let i=$i+1 # Something is incrementing our iteration counter
dd if=/dev/zero of=$i bs=10M # So here's the real work
sleep 2 # Ok, OP doesn't like it when his ramhog
# script runs out of ram (?) So let's slow it down.
done # Wait a minute, I though we were doing this forever? How can we be done?
因此,上面的评论已经说明了它的工作原理。只需将其复制并粘贴到 vi 或 nano 中,保存并运行sudo chmod 755 [filename]
,然后运行./[filename]
。尽情享受耗尽 RAM 的乐趣吧。