读取错误:0:资源暂时不可用
我有一个 bash 脚本,它多次提示用户输入,并在预计下一次输入时在后台处理输入。 我偶尔会收到此错误。
read error: 0: Resource temporarily unavailable
我怀疑脚本中的后台进程会导致此问题,因此我尝试添加 << dev/null 在后台运行的命令末尾,但这没有多大帮助。
./somescript.sh >> log.txt & < /dev/null
任何帮助将非常感激。
I have a bash script which prompts for user input multiple times and processes input in the background during the time the next input is expected.
I keep getting this error once in while.
read error: 0: Resource temporarily unavailable
I suspected the background processes in my script would be causing this so I tried putting a < dev/null at the end of the commands which run in the background,but that dint help much.
./somescript.sh >> log.txt & < /dev/null
Any help would be much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果不了解更多关于程序正在做什么的情况,很难诊断这一点,但是......
出于某种原因,我大脑的某些部分告诉我这是来自内核并且与分叉有关,但我无法固定我之所以这么认为。尝试运行你的脚本并观察你的内存使用情况(处理器也是如此,但这对我来说就像内存)。要获得比 top 更详细的统计信息,请运行
watch -d cat /proc/meminfo
并观察当您开始收到该错误时会发生什么。This is hard to diagnose without knowing more about what your program is doing, but...
For some reason some part of my brain is telling me that this is coming from the kernel and is related to forking, but I can't pin the reason I think that. Try running your script and watch your memory usage (processor too, but this feels like memory to me). For more detailed statistics [than top] run
watch -d cat /proc/meminfo
and watch what happens when you start to get that error.将错误简单重定向到 /dev/null 对我来说就成功了。
A simple redirection of error to /dev/null did the trick for me.