The specific locks through fcntl are based on each process and simply accumulate blocked intervals in the file for the given process. That is, the application must track the intervals, and any unlocked call for an interval unlocks it, regardless of how many blocking calls were made for that interval.
Worse, closing any file descriptor for a file undoes all locks in the file:
In addition to explicitly removing F_UNLCK, write locks are automatically released when the process terminates or the file descriptor is closed that refers to the file on which the locks are stored. This is bad: it means that a process can lose locks on a file like / etc / passwd or / etc / mtab, when for some reason the library function decides to open, read and close it.
source share