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