<s>
File	B-Application
locking	I-Application
is	O
a	O
mechanism	O
that	O
restricts	O
access	O
to	O
a	O
computer	B-Operating_System
file	I-Operating_System
,	O
or	O
to	O
a	O
region	O
of	O
a	O
file	O
,	O
by	O
allowing	O
only	O
one	O
user	O
or	O
process	B-Operating_System
to	O
modify	O
or	O
delete	O
it	O
at	O
a	O
specific	O
time	O
and	O
to	O
prevent	O
reading	O
of	O
the	O
file	O
while	O
it	O
's	O
being	O
modified	O
or	O
deleted	O
.	O
</s>
<s>
Systems	O
implement	O
locking	B-Operating_System
to	O
prevent	O
the	O
classic	O
interceding	O
update	O
scenario	O
,	O
which	O
is	O
a	O
typical	O
example	O
of	O
a	O
race	O
condition	O
,	O
by	O
enforcing	O
the	O
serialization	O
of	O
update	O
processes	O
to	O
any	O
given	O
file	O
.	O
</s>
<s>
Process	B-Operating_System
A	O
reads	O
a	O
customer	O
record	B-Application
from	O
a	O
file	O
containing	O
account	O
information	O
,	O
including	O
the	O
customer	O
's	O
account	O
balance	O
and	O
phone	O
number	O
.	O
</s>
<s>
Process	B-Operating_System
B	O
now	O
reads	O
the	O
same	O
record	B-Application
from	O
the	O
same	O
file	O
,	O
so	O
it	O
has	O
its	O
own	O
copy	O
.	O
</s>
<s>
Process	B-Operating_System
A	O
changes	O
the	O
account	O
balance	O
in	O
its	O
copy	O
of	O
the	O
customer	O
record	B-Application
and	O
writes	O
the	O
record	B-Application
back	O
to	O
the	O
file	O
.	O
</s>
<s>
Process	B-Operating_System
B	O
,	O
which	O
still	O
has	O
the	O
original	O
stale	O
value	O
for	O
the	O
account	O
balance	O
in	O
its	O
copy	O
of	O
the	O
customer	O
record	B-Application
,	O
updates	O
the	O
account	O
balance	O
and	O
writes	O
the	O
customer	O
record	B-Application
back	O
to	O
the	O
file	O
.	O
</s>
<s>
Process	B-Operating_System
B	O
has	O
now	O
written	O
its	O
stale	O
account-balance	O
value	O
to	O
the	O
file	O
,	O
causing	O
the	O
changes	O
made	O
by	O
process	B-Operating_System
A	O
to	O
be	O
lost	O
.	O
</s>
<s>
Most	O
operating	B-General_Concept
systems	I-General_Concept
support	O
the	O
concept	O
of	O
record	B-Operating_System
locking	I-Operating_System
,	O
which	O
means	O
that	O
individual	O
records	O
within	O
any	O
given	O
file	O
may	O
be	O
locked	O
,	O
thereby	O
increasing	O
the	O
number	O
of	O
concurrent	B-Operating_System
update	O
processes	O
.	O
</s>
<s>
Database	O
maintenance	O
uses	O
file	B-Application
locking	I-Application
,	O
whereby	O
it	O
can	O
serialize	O
access	O
to	O
the	O
entire	O
physical	O
file	O
underlying	O
a	O
database	O
.	O
</s>
<s>
Although	O
this	O
does	O
prevent	O
any	O
other	O
process	B-Operating_System
from	O
accessing	O
the	O
file	O
,	O
it	O
can	O
be	O
more	O
efficient	O
than	O
individually	O
locking	B-Operating_System
many	O
regions	O
in	O
the	O
file	O
by	O
removing	O
the	O
overhead	O
of	O
acquiring	O
and	O
releasing	O
each	O
lock	B-Operating_System
.	O
</s>
<s>
Poor	O
use	O
of	O
file	B-Application
locks	I-Application
,	O
like	O
any	O
computer	O
lock	B-Operating_System
,	O
can	O
result	O
in	O
poor	O
performance	O
or	O
in	O
deadlocks	B-Operating_System
.	O
</s>
<s>
File	B-Application
locking	I-Application
may	O
also	O
refer	O
to	O
additional	O
security	O
applied	O
by	O
a	O
computer	O
user	O
either	O
by	O
using	O
Windows	O
security	O
,	O
NTFS	B-Application
permissions	O
or	O
by	O
installing	O
a	O
third	O
party	O
file	B-Application
locking	I-Application
software	O
.	O
</s>
<s>
IBM	O
pioneered	O
file	B-Application
locking	I-Application
in	O
1963	O
for	O
use	O
in	O
mainframe	O
computers	O
using	O
OS/360	B-Application
,	O
where	O
it	O
was	O
termed	O
"	O
exclusive	O
control	O
"	O
.	O
</s>
<s>
Windows	O
inherits	O
the	O
semantics	O
of	O
share-access	O
controls	O
from	O
the	O
MS-DOS	B-Application
system	O
,	O
where	O
sharing	O
was	O
introduced	O
in	O
MS-DOS3.3	O
.	O
</s>
<s>
For	O
a	O
file	O
opened	O
with	O
shared	O
access	O
,	O
applications	O
may	O
then	O
use	O
byte-range	O
locking	B-Operating_System
to	O
control	O
access	O
to	O
specific	O
regions	O
of	O
the	O
file	O
.	O
</s>
<s>
Such	O
byte-range	O
locks	O
specify	O
a	O
region	O
of	O
the	O
file	O
(	O
offset	O
and	O
length	O
)	O
and	O
the	O
type	O
of	O
lock	B-Operating_System
(	O
shared	O
or	O
exclusive	O
)	O
.	O
</s>
<s>
For	O
applications	O
that	O
use	O
the	O
file	O
read/write	O
APIs	B-General_Concept
in	O
Windows	O
,	O
byte-range	O
locks	O
are	O
enforced	O
(	O
also	O
referred	O
to	O
as	O
mandatory	B-Operating_System
locks	I-Operating_System
)	O
by	O
the	O
file	O
systems	O
that	O
execute	O
within	O
Windows	O
.	O
</s>
<s>
For	O
applications	O
that	O
use	O
the	O
file	O
mapping	O
APIs	B-General_Concept
in	O
Windows	O
,	O
byte-range	O
locks	O
are	O
not	O
enforced	O
(	O
also	O
referred	O
to	O
as	O
advisory	B-Operating_System
locks	I-Operating_System
.	O
)	O
</s>
<s>
Byte-range	O
locking	B-Operating_System
may	O
also	O
have	O
other	O
side-effects	O
on	O
the	O
Windows	O
system	O
.	O
</s>
<s>
Improper	O
error-handling	O
in	O
an	O
application	O
program	O
can	O
lead	O
to	O
a	O
scenario	O
where	O
a	O
file	O
is	O
locked	O
(	O
either	O
using	O
"	O
share	O
"	O
access	O
or	O
with	O
byte-range	O
file	B-Application
locking	I-Application
)	O
and	O
cannot	O
be	O
accessed	O
by	O
other	O
applications	O
.	O
</s>
<s>
Byte-range	O
locking	B-Operating_System
type	O
is	O
determined	O
by	O
the	O
dwFlags	O
parameter	O
in	O
the	O
LockFileEx	O
function	O
used	O
to	O
lock	B-Operating_System
a	O
region	O
of	O
a	O
file	O
.	O
</s>
<s>
The	O
Windows	B-Library
API	I-Library
function	O
LockFile	O
can	O
also	O
be	O
used	O
and	O
acquires	O
an	O
exclusive	O
lock	B-Operating_System
on	O
the	O
region	O
of	O
the	O
file	O
.	O
</s>
<s>
an	O
EXE	O
,	O
COM	O
,	O
DLL	O
,	O
CPL	O
or	O
other	O
binary	O
program	O
file	O
format	O
)	O
is	O
normally	O
locked	O
by	O
the	O
operating	B-General_Concept
system	I-General_Concept
itself	O
,	O
preventing	O
any	O
application	O
from	O
modifying	O
or	O
deleting	O
it	O
.	O
</s>
<s>
Files	O
are	O
accessed	O
by	O
applications	O
in	O
Windows	O
by	O
using	O
file	B-Application
handles	I-Application
.	O
</s>
<s>
These	O
file	B-Application
handles	I-Application
can	O
be	O
explored	O
with	O
the	O
Process	B-Application
Explorer	I-Application
utility	O
.	O
</s>
<s>
Microsoft	B-Application
Windows	I-Application
XP	I-Application
and	O
Server	B-Application
2003	I-Application
editions	O
have	O
introduced	O
volume	O
snapshot	O
(	O
VSS	O
)	O
capability	O
to	O
NTFS	B-Application
,	O
allowing	O
open	O
files	O
to	O
be	O
accessed	O
by	O
backup	B-Application
software	I-Application
despite	O
any	O
exclusive	O
locks	O
.	O
</s>
<s>
However	O
,	O
unless	O
software	O
is	O
rewritten	O
to	O
specifically	O
support	O
this	O
feature	O
,	O
the	O
snapshot	O
will	O
be	O
crash	O
consistent	O
only	O
,	O
while	O
properly	O
supported	O
applications	O
can	O
assist	O
the	O
operating	B-General_Concept
system	I-General_Concept
in	O
creating	O
"	O
transactionally	O
consistent	O
"	O
snapshots	O
.	O
</s>
<s>
These	O
work	O
by	O
installing	O
their	O
own	O
drivers	B-Application
to	O
access	O
the	O
files	O
in	O
kernel	O
mode	O
.	O
</s>
<s>
Unix-like	B-Operating_System
operating	I-Operating_System
systems	I-Operating_System
(	O
including	O
Linux	B-Application
and	O
Apple	O
's	O
macOS	B-Application
)	O
do	O
not	O
normally	O
automatically	O
lock	B-Operating_System
open	O
files	O
.	O
</s>
<s>
Several	O
kinds	O
of	O
file-locking	O
mechanisms	O
are	O
available	O
in	O
different	O
flavors	O
of	O
Unix	O
,	O
and	O
many	O
operating	B-General_Concept
systems	I-General_Concept
support	O
more	O
than	O
one	O
kind	O
for	O
compatibility	O
.	O
</s>
<s>
Two	O
other	O
such	O
mechanisms	O
are	O
and	O
,	O
each	O
of	O
which	O
may	O
be	O
implemented	O
atop	O
fcntl	B-Application
or	O
may	O
be	O
implemented	O
separately	O
from	O
fcntl	B-Application
.	O
</s>
<s>
Although	O
some	O
types	O
of	O
locks	O
can	O
be	O
configured	O
to	O
be	O
mandatory	O
,	O
file	B-Application
locks	I-Application
under	O
Unix	O
are	O
by	O
default	O
advisory	O
.	O
</s>
<s>
In	O
other	O
words	O
,	O
file	B-Application
locks	I-Application
lock	B-Operating_System
out	O
other	O
file	O
lockers	O
only	O
,	O
not	O
I/O	O
.	O
</s>
<s>
Two	O
kinds	O
of	O
locks	O
are	O
offered	O
:	O
shared	B-Operating_System
locks	I-Operating_System
and	O
exclusive	O
locks	O
.	O
</s>
<s>
In	O
the	O
case	O
of	O
fcntl	B-Application
,	O
different	O
kinds	O
of	O
locks	O
may	O
be	O
applied	O
to	O
different	O
sections	O
(	O
byte	O
ranges	O
)	O
of	O
a	O
file	O
,	O
or	O
else	O
to	O
the	O
whole	O
file	O
.	O
</s>
<s>
Shared	B-Operating_System
locks	I-Operating_System
can	O
be	O
held	O
by	O
multiple	O
processes	O
at	O
the	O
same	O
time	O
,	O
but	O
an	O
exclusive	O
lock	B-Operating_System
can	O
only	O
be	O
held	O
by	O
one	O
process	B-Operating_System
,	O
and	O
cannot	O
coexist	O
with	O
a	O
shared	B-Operating_System
lock	I-Operating_System
.	O
</s>
<s>
To	O
acquire	O
a	O
shared	B-Operating_System
lock	I-Operating_System
,	O
a	O
process	B-Operating_System
must	O
wait	O
until	O
no	O
processes	O
hold	O
any	O
exclusive	O
locks	O
.	O
</s>
<s>
To	O
acquire	O
an	O
exclusive	O
lock	B-Operating_System
,	O
a	O
process	B-Operating_System
must	O
wait	O
until	O
no	O
processes	O
hold	O
either	O
kind	O
of	O
lock	B-Operating_System
.	O
</s>
<s>
Unlike	O
locks	O
created	O
by	O
fcntl	B-Application
,	O
those	O
created	O
by	O
flock	O
are	O
preserved	O
across	O
forks	O
,	O
making	O
them	O
useful	O
in	O
forking	O
servers	O
.	O
</s>
<s>
It	O
is	O
therefore	O
possible	O
for	O
more	O
than	O
one	O
process	B-Operating_System
to	O
hold	O
an	O
exclusive	O
lock	B-Operating_System
on	O
the	O
same	O
file	O
,	O
provided	O
these	O
processes	O
share	O
a	O
filial	O
relationship	O
and	O
the	O
exclusive	O
lock	B-Operating_System
was	O
initially	O
created	O
in	O
a	O
single	O
process	B-Operating_System
before	O
being	O
duplicated	O
across	O
a	O
fork	O
.	O
</s>
<s>
Shared	B-Operating_System
locks	I-Operating_System
are	O
sometimes	O
called	O
"	O
read	B-Operating_System
locks	I-Operating_System
"	O
and	O
exclusive	O
locks	O
are	O
sometimes	O
called	O
"	O
write	B-Operating_System
locks	I-Operating_System
"	O
.	O
</s>
<s>
File	B-Application
locks	I-Application
apply	O
to	O
the	O
actual	O
file	O
,	O
rather	O
than	O
the	O
file	O
name	O
.	O
</s>
<s>
Together	O
with	O
non-mandatory	O
locking	B-Operating_System
,	O
this	O
leads	O
to	O
great	O
flexibility	O
in	O
accessing	O
files	O
from	O
multiple	O
processes	O
.	O
</s>
<s>
On	O
the	O
other	O
hand	O
,	O
the	O
cooperative	O
locking	B-Operating_System
approach	O
can	O
lead	O
to	O
problems	O
when	O
a	O
process	B-Operating_System
writes	O
to	O
a	O
file	O
without	O
obeying	O
file	B-Application
locks	I-Application
set	O
by	O
other	O
processes	O
.	O
</s>
<s>
For	O
this	O
reason	O
,	O
some	O
Unix-like	B-Operating_System
operating	I-Operating_System
systems	I-Operating_System
also	O
offer	O
limited	O
support	O
for	O
mandatory	O
locking	B-Operating_System
.	O
</s>
<s>
On	O
such	O
systems	O
,	O
a	O
file	O
whose	O
setgid	O
bit	O
is	O
on	O
but	O
whose	O
group	O
execution	O
bit	O
is	O
off	O
when	O
that	O
file	O
is	O
opened	O
will	O
be	O
subject	O
to	O
automatic	O
mandatory	O
locking	B-Operating_System
if	O
the	O
underlying	O
filesystem	O
supports	O
it	O
.	O
</s>
<s>
However	O
,	O
non-local	O
NFS	B-Protocol
partitions	O
tend	O
to	O
disregard	O
this	O
bit	O
.	O
</s>
<s>
If	O
a	O
file	O
is	O
subject	O
to	O
mandatory	O
locking	B-Operating_System
,	O
attempts	O
to	O
read	O
from	O
a	O
region	O
that	O
is	O
locked	O
with	O
an	O
exclusive	O
lock	B-Operating_System
,	O
or	O
to	O
write	O
to	O
a	O
region	O
that	O
is	O
locked	O
with	O
a	O
shared	O
or	O
exclusive	O
lock	B-Operating_System
,	O
will	O
block	O
until	O
the	O
lock	B-Operating_System
is	O
released	O
.	O
</s>
<s>
This	O
strategy	O
first	O
originated	O
in	O
SystemV	O
,	O
and	O
can	O
be	O
seen	O
today	O
in	O
the	O
Solaris	B-Application
,	O
HP-UX	B-Application
,	O
and	O
Linux	B-Application
operating	I-Application
systems	I-Application
.	O
</s>
<s>
It	O
is	O
not	O
part	O
of	O
POSIX	O
,	O
however	O
,	O
and	O
BSD-derived	O
operating	B-General_Concept
systems	I-General_Concept
such	O
as	O
FreeBSD	B-Operating_System
,	O
OpenBSD	B-Operating_System
,	O
NetBSD	B-Device
,	O
and	O
Apple	O
's	O
macOS	B-Application
do	O
not	O
support	O
it	O
.	O
</s>
<s>
Linux	B-Application
also	O
supports	O
mandatory	O
locking	B-Operating_System
through	O
the	O
special	O
-o	O
mand	O
parameter	O
for	O
file	O
system	O
mounting	O
(	O
)	O
,	O
but	O
this	O
is	O
rarely	O
used	O
.	O
</s>
<s>
Some	O
Unix-like	B-Operating_System
operating	I-Operating_System
systems	I-Operating_System
prevent	O
attempts	O
to	O
open	O
the	O
executable	O
file	O
of	O
a	O
running	O
program	O
for	O
writing	O
;	O
this	O
is	O
a	O
third	O
form	O
of	O
locking	B-Operating_System
,	O
separate	O
from	O
those	O
provided	O
by	O
fcntl	B-Application
and	O
flock	O
.	O
</s>
<s>
More	O
than	O
one	O
process	B-Operating_System
can	O
hold	O
an	O
exclusive	O
flock	O
on	O
a	O
given	O
file	O
if	O
the	O
exclusive	O
lock	B-Operating_System
was	O
duplicated	O
across	O
a	O
later	O
fork	O
.	O
</s>
<s>
Mandatory	B-Operating_System
locks	I-Operating_System
have	O
no	O
effect	O
on	O
the	O
unlink	O
system	O
call	O
.	O
</s>
<s>
Consequently	O
,	O
certain	O
programs	O
may	O
,	O
effectively	O
,	O
circumvent	O
mandatory	O
locking	B-Operating_System
.	O
</s>
<s>
Whether	O
and	O
how	O
flock	O
locks	O
work	O
on	O
network	O
filesystems	O
,	O
such	O
as	O
NFS	B-Protocol
,	O
is	O
implementation	O
dependent	O
.	O
</s>
<s>
On	O
BSD	B-Operating_System
systems	O
,	O
flock	O
calls	O
on	O
a	O
file	B-Application
descriptor	I-Application
open	O
to	O
a	O
file	O
on	O
an	O
NFS-mounted	O
partition	O
are	O
successful	O
no-ops	B-Language
.	O
</s>
<s>
On	O
Linux	B-Application
prior	O
to	O
2.6.12	O
,	O
flock	O
calls	O
on	O
NFS	B-Protocol
files	O
would	O
act	O
only	O
locally	O
.	O
</s>
<s>
Kernel2.6.12	O
and	O
above	O
implement	O
flock	O
calls	O
on	O
NFS	B-Protocol
files	O
using	O
POSIX	O
byte-range	O
locks	O
.	O
</s>
<s>
These	O
locks	O
will	O
be	O
visible	O
to	O
other	O
NFS	B-Protocol
clients	O
that	O
implement	O
fcntl-style	O
POSIX	O
locks	O
,	O
but	O
invisible	O
to	O
those	O
that	O
do	O
not	O
.	O
</s>
<s>
Lock	B-Operating_System
upgrades	O
and	O
downgrades	O
release	O
the	O
old	O
lock	B-Operating_System
before	O
applying	O
the	O
new	O
lock	B-Operating_System
.	O
</s>
<s>
If	O
an	O
application	O
downgrades	O
an	O
exclusive	O
lock	B-Operating_System
to	O
a	O
shared	B-Operating_System
lock	I-Operating_System
while	O
another	O
application	O
is	O
blocked	O
waiting	O
for	O
an	O
exclusive	O
lock	B-Operating_System
,	O
the	O
latter	O
application	O
may	O
get	O
the	O
exclusive	O
lock	B-Operating_System
and	O
lock	B-Operating_System
the	O
first	O
application	O
out	O
.	O
</s>
<s>
This	O
means	O
that	O
lock	B-Operating_System
downgrades	O
can	O
block	O
,	O
which	O
may	O
be	O
counter-intuitive	O
.	O
</s>
<s>
All	O
fcntl	B-Application
locks	O
associated	O
with	O
a	O
file	O
for	O
a	O
given	O
process	B-Operating_System
are	O
removed	O
when	O
any	O
file	B-Application
descriptor	I-Application
for	O
that	O
file	O
is	O
closed	O
by	O
that	O
process	B-Operating_System
,	O
even	O
if	O
a	O
lock	B-Operating_System
was	O
never	O
requested	O
for	O
that	O
file	B-Application
descriptor	I-Application
.	O
</s>
<s>
Also	O
,	O
fcntl	B-Application
locks	O
are	O
not	O
inherited	O
by	O
a	O
child	O
process	B-Operating_System
.	O
</s>
<s>
The	O
fcntl	B-Application
close	O
semantics	O
are	O
particularly	O
troublesome	O
for	O
applications	O
that	O
call	O
subroutine	O
libraries	O
that	O
may	O
access	O
files	O
.	O
</s>
<s>
Preservation	O
of	O
the	O
lock	B-Operating_System
status	O
on	O
open	O
file	B-Application
descriptors	I-Application
passed	O
to	O
another	O
process	B-Operating_System
using	O
a	O
Unix	B-Protocol
domain	I-Protocol
socket	I-Protocol
is	O
implementation	O
dependent	O
.	O
</s>
<s>
One	O
source	O
of	O
lock	B-Operating_System
failure	O
occurs	O
when	O
buffered	O
I/O	O
has	O
buffers	O
assigned	O
in	O
the	O
user	O
's	O
local	O
workspace	O
,	O
rather	O
than	O
in	O
an	O
operating	B-General_Concept
system	I-General_Concept
buffer	O
pool	O
.	O
</s>
<s>
The	O
best	O
solution	O
to	O
this	O
problem	O
is	O
to	O
use	O
unbuffered	O
I/O	O
(	O
read	O
and	O
write	O
)	O
with	O
flock	O
,	O
which	O
also	O
means	O
using	O
lseek	B-Application
instead	O
of	O
fseek	O
and	O
ftell	O
.	O
</s>
<s>
In	O
AmigaOS	B-Application
,	O
a	O
lock	B-Operating_System
on	O
a	O
file	O
(	O
or	O
directory	O
)	O
can	O
be	O
acquired	O
using	O
the	O
Lock	B-Operating_System
function	O
(	O
in	O
the	O
dos.library	O
)	O
.	O
</s>
<s>
A	O
lock	B-Operating_System
can	O
be	O
shared	O
(	O
other	O
processes	O
can	O
read	O
the	O
file/directory	O
,	O
but	O
ca	O
n't	O
modify	O
or	O
delete	O
it	O
)	O
,	O
or	O
exclusive	O
so	O
that	O
only	O
the	O
process	B-Operating_System
which	O
successfully	O
acquires	O
the	O
lock	B-Operating_System
can	O
access	O
or	O
modify	O
the	O
object	O
.	O
</s>
<s>
The	O
lock	B-Operating_System
is	O
on	O
the	O
whole	O
object	O
and	O
not	O
part	O
of	O
it	O
.	O
</s>
<s>
The	O
lock	B-Operating_System
must	O
be	O
released	O
with	O
the	O
UnLock	O
function	O
:	O
unlike	O
in	O
Unix	O
,	O
the	O
operating	B-General_Concept
system	I-General_Concept
does	O
not	O
implicitly	O
unlock	O
the	O
object	O
when	O
the	O
process	B-Operating_System
terminates	O
.	O
</s>
<s>
Shell	B-Language
scripts	I-Language
and	O
other	O
programs	O
often	O
use	O
a	O
strategy	O
similar	O
to	O
the	O
use	O
of	O
file	B-Application
locking	I-Application
:	O
creation	O
of	O
lock	B-Operating_System
files	O
,	O
which	O
are	O
files	O
whose	O
contents	O
are	O
irrelevant	O
(	O
although	O
often	O
one	O
will	O
find	O
the	O
process	B-Operating_System
identifier	I-Operating_System
of	O
the	O
holder	O
of	O
the	O
lock	B-Operating_System
in	O
the	O
file	O
)	O
and	O
whose	O
sole	O
purpose	O
is	O
to	O
signal	O
by	O
their	O
presence	O
that	O
some	O
resource	O
is	O
locked	O
.	O
</s>
<s>
A	O
lock	B-Operating_System
file	O
is	O
often	O
the	O
best	O
approach	O
if	O
the	O
resource	O
to	O
be	O
controlled	O
is	O
not	O
a	O
regular	O
file	O
at	O
all	O
,	O
so	O
using	O
methods	O
for	O
locking	B-Operating_System
files	O
does	O
not	O
apply	O
.	O
</s>
<s>
For	O
example	O
,	O
a	O
lock	B-Operating_System
file	O
might	O
govern	O
access	O
to	O
a	O
set	O
of	O
related	O
resources	O
,	O
such	O
as	O
several	O
different	O
files	O
,	O
directories	O
,	O
a	O
group	O
of	O
disk	O
partitions	O
,	O
or	O
selected	O
access	O
to	O
higher	O
level	O
protocols	O
like	O
servers	O
or	O
database	O
connections	O
.	O
</s>
<s>
When	O
using	O
lock	B-Operating_System
files	O
,	O
care	O
must	O
be	O
taken	O
to	O
ensure	O
that	O
operations	O
are	O
atomic	B-General_Concept
.	O
</s>
<s>
To	O
obtain	O
a	O
lock	B-Operating_System
,	O
the	O
process	B-Operating_System
must	O
verify	O
that	O
the	O
lock	B-Operating_System
file	O
does	O
not	O
exist	O
and	O
then	O
create	O
it	O
,	O
whilst	O
preventing	O
another	O
process	B-Operating_System
from	O
creating	O
it	O
in	O
the	O
meantime	O
.	O
</s>
<s>
Lock	B-Operating_System
files	O
are	O
often	O
named	O
with	O
a	O
tilde	O
(	O
~	O
)	O
prefixed	O
to	O
the	O
name	O
of	O
the	O
file	O
they	O
are	O
locking	B-Operating_System
,	O
or	O
a	O
duplicate	O
of	O
the	O
full	O
file	O
name	O
suffixed	O
with	O
.LCK	O
.	O
</s>
<s>
If	O
they	O
are	O
locking	B-Operating_System
a	O
resource	O
other	O
than	O
a	O
file	O
,	O
they	O
may	O
be	O
named	O
more	O
arbitrarily	O
.	O
</s>
<s>
Certain	O
Mozilla	B-Operating_System
products	O
(	O
such	O
as	O
Firefox	B-Application
,	O
Thunderbird	O
,	O
Sunbird	O
)	O
use	O
this	O
type	O
of	O
file	O
resource	O
lock	B-Operating_System
mechanism	O
(	O
using	O
a	O
temporary	O
file	O
named	O
"	O
parent.lock	B-Application
"	O
.	O
)	O
</s>
<s>
An	O
unlocker	O
is	O
a	O
utility	O
used	O
to	O
determine	O
what	O
process	B-Operating_System
is	O
locking	B-Operating_System
a	O
file	O
,	O
and	O
displays	O
a	O
list	O
of	O
processes	O
as	O
well	O
as	O
choices	O
on	O
what	O
to	O
do	O
with	O
the	O
process	B-Operating_System
(	O
kill	O
task	O
,	O
unlock	O
,	O
etc	O
.	O
)	O
</s>
<s>
On	O
some	O
Unix-like	B-Operating_System
systems	I-Operating_System
,	O
utilities	O
such	O
as	O
fstat	O
and	O
lockf	O
can	O
be	O
used	O
to	O
inspect	O
the	O
state	O
of	O
file	B-Application
locks	I-Application
by	O
process	B-Operating_System
,	O
by	O
filename	O
,	O
or	O
both	O
.	O
</s>
<s>
In	O
version	B-Architecture
control	I-Architecture
systems	I-Architecture
file	B-Application
locking	I-Application
is	O
used	O
to	O
prevent	O
two	O
users	O
changing	O
the	O
same	O
file	O
version	O
in	O
parallel	O
and	O
then	O
when	O
saving	O
,	O
the	O
second	O
user	O
to	O
overwrite	O
what	O
first	O
user	O
changed	O
.	O
</s>
<s>
A	O
user	O
wanting	O
to	O
change	O
the	O
file	O
performs	O
an	O
unlock	O
(	O
also	O
called	O
checkout	O
)	O
operation	O
,	O
and	O
until	O
a	O
check-in	O
(	O
store	O
)	O
operation	O
is	O
done	O
,	O
or	O
the	O
lock	B-Operating_System
is	O
reverted	O
,	O
nobody	O
else	O
is	O
allowed	O
to	O
unlock	O
the	O
file	O
.	O
</s>
