产生读取错误 [英] Generate a read error
问题描述
通过写入 /dev/full
在测试套件中生成写入错误很简单.是否有产生读取错误的好技术?我目前正在使用 LD_PRELOAD 来覆盖 read
但这似乎太复杂且不可移植(不是说/dev/full 是可移植的......).
It's simple to generate a write error in a test suite by writing to /dev/full
. Is there a good technique to generate a read error? I'm currently using LD_PRELOAD to override read
but that seems too complicated and non-portable (not that /dev/full is portable...).
推荐答案
除了从目录中读取(如之前的答案中提到的)之外,您还可以尝试读取 /proc/self/mem
以获取一个错误(这应该会让你在 Linux 上获得一个 EIO
).有关说明,请参阅:https://unix.stackexchange.com/a/6302
Besides reading from a directory (as mentioned in a previous answer) you can try to read /proc/self/mem
to get an error (this should get you an EIO
on Linux). For an explanation, please see: https://unix.stackexchange.com/a/6302
这篇关于产生读取错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!