Title. What happens if we try to unlock an already unlocked file using flock? That is to say, when we already used a flock(file, LOCK_UN) and we try to use it again!
This in C. Is the behavior unexpected? Does it give an error? Does it do nothing?
Thanks!
The
flock()
is part of BSD, otherwise not standardized, and specified only as good as it is specified in the BSD documentation.Yet, it is a real kernel syscall and as such is capable of detecting all types of misbehavior on part of the user-space applications. Including the double unlock.
If you want a well defined, yet not widely supported function, check the POSIX'
lockf()
.