红联Linux门户
Linux帮助

linux使用flock文件锁解决crontab冲突问题

发布时间:2016-11-04 11:47:22来源:linux网站作者:zkaipmoo
flock命令提供了文件锁的功能。命令参数如下:
[hailong@vhost ~]$ flock -h
flock (util-Linux 2.13-pre7)
Usage: flock [-sxun][-w #] fd#
flock [-sxon][-w #] file [-c] command…
-s –shared Get a shared lock
-x –exclusive Get an exclusive lock
-u –unlock Remove a lock
-n –nonblock Fail rather than wait
-w –timeout Wait for a limited amount of time
-o –close Close file descriptor before running command
-c –command Run a single command string through the shell
-h –help Display this text
-V –version Display version
 
使用flock控制并发冲突,我们的crond配置如下:
*/1 * * * * root flock -xn /tmp/mytest.lock -c 'php ./test.php'
 
本文永久更新地址:http://www.linuxdiyf.com/linux/25727.html