This usage of flock
uses the script file of the executable itself ($0
) as its own lock file. Since file locking is based on a mechanism besides the contents of the file, this is possible. Using <
instead of >
or >>
assumes that it already exists and does not need to be created first; since the script typically exists and is readable during its execution (anything else is pathological for sure), this is a safe assumption.
Using 200<
opens $0
for reading and redirects it to file descriptor 200. Inside the subshell (formed with the large ( ... )
) the flock
command then uses this open file descriptor for file locking.