Miguel Carvalho
Miguel Carvalho

Reputation: 13

What happens if we try to unlock an already unlocked file using flock? C lang

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!

Upvotes: 0

Views: 315

Answers (1)

Dummy00001
Dummy00001

Reputation: 17430

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().

Upvotes: 1

Related Questions