<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Madison Kelly wrote:
<blockquote cite="mid:4AC4D1A0.9020507@alteeve.com" type="cite">Does
perl support file locking? If so, how does an active file handle know
when another perl process has locked a file? Will it pause and wait for
the file to be unlocked?
  <br>
</blockquote>
Kind of. The flock() function that does the main magic is usually
available, but it does delegate a lot to the operating system or C
runtime, and these vary a lot. The answer to the "how does it know" bit
is at the OS level. Under a
Perl handle is an OS handle, and that is what is used to ensure
exclusive access. Generally Perl can't find the other process, but the
OS prevents any other process from using the file.<br>
<br>
If you're on a UNIX-style system, flock() is usually OK (except on
shared file systems), but on Windows, I have had problems with the
emulated versions. Windows has its own API access to its own mutex
systems, which are reliable but generally unpleasant to look at. I now
tend to use a SQLite database, which provides exclusive transactions,
as a way of synchronizing between separate processes, and I share data
between processes that way too. I have learnt to avoid depending too
much on Perl file system access on Windows. I have no idea how SQLite
does what it does internally, but it seems a very simple solution to
code, and one which is very reliable. <br>
<br>
I've also used MLDBM::Sync in the past, but with less success. I prefer
using higher level modules to using flock() directly, as they often add
additional logic that boosts portability. My experiences with direct
flock() coding were not positive or rewarding. <br>
<br>
All the best<br>
Stuart<br>
-- <br>
<span style="color: rgb(102, 0, 0);">Stuart Watt<br>
ARM Product Developer<br>
Information Balance</span><br>
</body>
</html>