flock

发布时间: 更新时间: 总字数:279 阅读时间:1m 作者:IP:上海 网址

flock命令Linux下的文件锁,一般和crontab一起使用,防止重复执行

help

flock --help ...

参数说明:

  • -s, --shared 获取一个共享锁
  • -x, --exclusive 获取一个排它锁
  • -u, --unlock 手动释放锁,一般情况下系统会自动解锁
  • -n, --nonblock 非阻塞模式,当获取锁失败时,返回 1
  • -w, --timeout <secs> 设置阻塞时间,当超时时,退出阻塞模式,返回 1
  • -o, --close close file descriptor before running command
  • -c, --command <command> shell 命令

示例

  • 与 contab 一同使用,防止重复
* * * * * (flock -xn /tmp/test.lock -c "bash <path-of>/test.sh")
本文总阅读量 次 本站总访问量 次 本站总访客数