
78
CHAPTER 3 ADVANCED FILE AND DIRECTORY PROCESSING, AND THE REGISTRY
Using File Locks
File locking examples are deferred until Chapter 6, which covers process manage-
ment. Programs 4–2, 6–4, 6–5, and 6–6 use locks to ensure that only one process
at a time can modify a file.
UNIX has advisory file locking; an attempt to obtain a lock may fail (the logic is
the same as in Table 3–1), but the process can still perform the I/O. Therefore,
UNIX can achieve locking between cooperating processes, but any other process
can violate the protocol.
To obtain an advisory lock, use options to the
function. The commands (the
second parameter) are
, (to wait),