Choosing a Lock Type

Mandatory locking suspends a process until the requested file segments are free. Advisory locking returns a result indicating whether the lock was obtained or not. A process can ignore the result of advisory locking. You cannot use both mandatory and advisory file locking on the same file at the same time. The mode of a file at the time the file is opened determines whether locks on a file are treated as mandatory or advisory.

The fcntl locking call is more portable, powerful, and less easy to use than lockf locking call. fcntl is specified in POSIX 1003.1 standard. lockf is compatible with older applications. For more information, see the fcntl(2), lockf(3C), fcntl(2), and lockf(3C) man pages.