CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Frequently Asked Questions:
How can I lock a file?

 



Jasmine
Administrator

Jan 26, 2001, 10:23 AM

Post #1 of 1 (1766 views)
How can I lock a file? Can't Post

(From the Perl FAQ)

How can I lock a file?

Perl's builtin flock() function (see the perlfunc manpage for details) will call flock(2) if that exists, fcntl(2) if it doesn't (on perl version 5.004 and later), and lockf(3) if neither of the two previous system calls exists. On some systems, it may even use a different form of native locking. Here are some gotchas with Perl's flock():

1. Produces a fatal error if none of the three system calls (or their close equivalent) exists.

2. lockf(3) does not provide shared locking, and requires that the filehandle be open for writing (or appending, or read/writing).

3. Some versions of flock() can't lock files over a network (e.g. on NFS file systems), so you'd need to force the use of fcntl(2) when you build Perl. See the flock entry of the perlfunc manpage, and the INSTALL file in the source distribution for information on building Perl to do this.


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives