96 lines
2.2 KiB
Groff
96 lines
2.2 KiB
Groff
.TH lock "" "" "/rdb Command"
|
|
.PC "Lock a record or field of a file"
|
|
\fBlock \fIfilename processid from to indexfrom indexto\fR
|
|
.PP
|
|
.II "record locking"
|
|
The command
|
|
.B lock
|
|
locks
|
|
.I filename
|
|
by writing a row into the lock file \fB/tmp/L\fIfilename\fR,
|
|
which contains one line for each locked record or field.
|
|
Its command line contains the following arguments:
|
|
.IP \fIprocessid\fR
|
|
The process identifier of the program that locks
|
|
.IR filename .
|
|
.IP \fIfrom\fR
|
|
The beginning point of the bytes to be locked.
|
|
.IP \fIto\fR
|
|
The end point of the bytes to be locked.
|
|
.IP \fIindexbegin\fR
|
|
The beginning point of the index entry for the data being locked.
|
|
.IP \fIindexend\fR
|
|
The end point of the index entry for the data being locked.
|
|
.PP
|
|
When a process attempts to lock a string of bytes that is already locked,
|
|
.B lock
|
|
returns an error condition.
|
|
You can test for this by using the COHERENT command
|
|
.B test
|
|
to test the shell variable \fB$?\fR.
|
|
.SH Example
|
|
Let's use
|
|
.B lock
|
|
on table
|
|
.BR inventory ,
|
|
which appears as follows:
|
|
.DM
|
|
Item Amount Cost Value Description
|
|
---- ------ ---- ----- --------------
|
|
1 3 50 150 rubber gloves
|
|
2 100 5 500 test tubes
|
|
3 5 80 400 clamps
|
|
4 23 19 437 plates
|
|
5 99 24 2376 cleaning cloth
|
|
6 89 147 13083 bunsen burners
|
|
7 5 175 875 scales
|
|
.DE
|
|
.PP
|
|
First, use
|
|
.B seek
|
|
to locate the record and return the offset and size, as follows:
|
|
.DM
|
|
LOCATION=`echo 5 | seek -mb inventory Item`
|
|
echo $LOCATION
|
|
207 245 0 8
|
|
.DE
|
|
.PP
|
|
This means that the record is offset 207 bytes into file
|
|
.BR inventory ,
|
|
and that it is 38 bytes long, ending at byte 245.
|
|
The 0 and 8 mean that there is no secondary index file.
|
|
.PP
|
|
Now we can call
|
|
.B lock
|
|
to lock the record:
|
|
.DM
|
|
lock inventory $$ $LOCATION
|
|
.DE
|
|
.PP
|
|
Note that we use the shell variable
|
|
.B $LOCATION
|
|
to supply the arguments
|
|
.I from
|
|
and
|
|
.IR to .
|
|
We also use the built-in shell variable \fB$$\fR to
|
|
write the process identifier on the command line.
|
|
.PP
|
|
The lock
|
|
.B /tmp/Linventory
|
|
has the following contents:
|
|
.DM
|
|
207 245 0 8
|
|
.DE
|
|
.SH "See Also"
|
|
.B
|
|
seek,
|
|
unlock
|
|
.R
|
|
.br
|
|
COHERENT Lexicon:
|
|
.B
|
|
test
|
|
.R
|
|
.SO lock
|