Before discussing how to use record locking, let us first define a few terms.
A contiguous set of bytes in a file.
The UNIX operating system does not impose any record structure
This may be done by the programs that use the files.
Processes that work together in some well-defined
fashion to accomplish the tasks at hand.
Processes that share files must request permission
to access the files before using them.
File access permissions must be carefully
set to restrict noncooperating processes from accessing those files.
will be used interchangeably with
to refer to a task obeying such protocols.
Read (Share) Locks
These are used to gain limited access to sections of files.
When a read lock is put on a record, other processes may also read
lock that record, in whole or in part.
No other process, however, may have or obtain a write lock on an overlapping
section of the file.
If a process holds a read lock it may assume
that no other process will be writing or updating that record at the same time.
This access method also lets many processes read the given record.
This might be necessary when searching a file, without the contention
involved if a write or exclusive lock were used.
Write (Exclusive) Locks
These are used to gain complete control over sections of files.
When a write lock is put on a record, no other process may read or
write lock that record, in whole or in part.
If a process holds a write lock it may assume
that no other process will be reading or writing that record at the same time.
A form of record locking that does
not interact with the I/O
Advisory locking is not enforced, for example, by
creat, open, read, or write.
The control over records is accomplished by requiring an
appropriate record lock request before I/O operations.
If appropriate requests are always made by all processes accessing the
file, then the accessibility of the file will be controlled by the interaction
of these requests.
Advisory locking depends on the individual processes to enforce the record
it does not require an accessibility check at the time of each I/O
A form of record locking that does interact with the I/O
Access to locked records is enforced
by the creat,
open, read and write
If a record is locked, then access of that record by any other process is
restricted according to the type of lock on the record.
The control over records should still be performed explicitly by
requesting an appropriate record lock before I/O operations, but an
additional check is made by the system before each I/O operation to
ensure the record locking protocol is being honored.
Mandatory locking offers an extra synchronization check, but at
the cost of some additional system overhead.
File and record locking
© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 27 April 2004