简体   繁体   English

Bash -e是否存在检查阻止文件删除?

[英]Bash -e existence check blocks file deletion?

I have a process that creates a lockfile ~/process.lock 我有一个创建锁文件〜/ process.lock的进程

I wanted to execute a command as soon that process ended, so i wrote 我想在该过程结束后立即执行命令,所以我写了

while [ -e ~/process.lock ]
do
:
done
#do stuff after process has ended

Apparently this prevented process.lock being deleted by the parent process. 显然,这防止了父进程删除process.lock。 Did this happen? 发生了吗? If yes, why? 如果是,为什么? and what is the correct way to do this. 正确的方法是什么

Indeed, the problem is probably not the -e test, but the tight loop, delaying anything else from happening, especially on a system with only a single (logical) core. 确实,问题可能不是-e测试,而是紧密的循环,这延迟其他事情的发生,尤其是在只有单个(逻辑)内核的系统上。 Adding sleep will undoubtedly help, and you may find that the sleep command accepts arguments less than 1, so you can notice the file disappear fairly quickly. 添加睡眠无疑会有所帮助,您可能会发现sleep命令接受的参数小于1,因此您可以注意到文件很快消失了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM