flock (util-linux 2.13-pre7)
Usage: flock [-sxun][-w #] fd#
flock [-sxon][-w #] file [-c] command...
-s --shared Get a shared lock
#共享鎖,在定向為某文件的FD上設置共享鎖而未釋放鎖的時間內,其他進程試圖在定向為此文件的FD上設置獨占鎖的請求失敗,而其他進程試圖在定向為此文件的FD上設置共享鎖的請求會成功
-x --exclusive Get an exclusive lock
#獨占或排他鎖,在定向為某文件的FD上設置獨占鎖而未釋放鎖的時間內,其他進程試圖在定向為此文件的FD上設置共享鎖或獨占鎖都會失敗。只要未設置-s參數,此參數默認被設置
-u --unlock Remove a lock
#手動解鎖,一般情況不必須,當FD關閉時,系統會自動解鎖,此參數用于腳本命令一部分需要異步執行,一部分可以同步執行的情況
-n --nonblock Fail rather than wait
#為非阻塞模式,當試圖設置鎖失敗,采用非阻塞模式,直接返回1,
-w --timeout Wait
for
a limited amount of
time
#設置阻塞超時,當超過設置的秒數,就跳出阻塞,返回1
-o --close Close file descriptor before running command
-c --command Run a single command string through the shell 執行其后的comand
-h --help Display
this
text
-V --version Display version