Record Locking

The BSD flock(2) approach provides improved performance over the lock file but still suffers from the fact that it locks the entire file.

Even better performance can be obtained when the regions of the file are locked instead of the entire file. System V provided the lockf(2) function to accomplish this. Later, POSIX defined yet another application interface using the fcntl(2) function.

To visualize locked regions, review Figure 5.1, in which three processes successfully obtained region locks. The execution of the fourth process was suspended because its request to lock a region overlapped with another granted lock.

Locking with lockf(2)

The lockf(2) function is not documented under FreeBSD, presumably because it was a System V ...

Get Advanced UNIX Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.