flock behavior on BSD - question
ORESoftware opened this issue · 2 comments
ORESoftware commented
So I have this code that I stole for Linux. I am hoping that it works on BSD:
(
flock -x 200
my_file="$HOME/.locking/counts/counts.json"
touch "$my_file"
my_str=$(cat "$my_file");
typeset -i my_num="${my_str:-"1"}"
echo "$((my_num=my_num+$1))" | tee "$my_file"
) 200 >>/var/lock/mylockfile
my question is - can you explain what this syntax is doing? The 200 is not being passed to flock as a timeout is it? So what is the 200 doing?
ORESoftware commented
well in any case I got this error with the above syntax (although it works on Ubuntu):
flock: illegal option -- x
usage: flock [-suno] [-w secs] <file> <command> [<arguments>...]
flock [-suno] [-w secs] <file-descriptor-number>
josephholsten commented
At that time, we didn't support the -x
flag, it was was a redundant way of specifying the default exclusive lock.
But now we support redundantly specifying the lock should be exclusive to your heart's content!