如何在Shell中设置文件锁?
最近在发现过一次监控脚本挂住的问题,就整理了此文,希望对有需要的朋友一些借鉴。在 Bash Shell 中的实现:# This is to examine whether the lockfile existed[ -f "${0}.lock" ] && exit -1
# Create the lock file
lockfile ${0}.lock
# Your code goes here!
#...
# Release the lock file manually
rm -f ${0}.lockPython 和 Perl 中的实现样例请参考 这里的原文
实现此目的是避免同一个脚本重复执行引起的进程积累,导致大量系统资源被消耗掉。
在 crontab 和 系统监控中尤其要注意这个问题。 以避免对线上环境造成影响。 好文
页:
[1]