Locking Files - Can I Do It?
Posted on 2001-06-16
Imagine I have a file containing some data. A CGI script is called and that data is edited. The seqence is like this:-
Proccess Data With CGI Inputs
Overwrites With New Data
Here's the problem. The proccessing takes a little while. It is possible that another instance of the script could be called during this time, which would of course mess it up (as part of the data is an incrementing value - and yes, I do need to keep it as one file).
Does anyone know of any way in Perl to "lock" a file so no other script can access it while the other is running and proccessing it? It is essential that the other script will wait for the file to be available to, not just dump the proccessing! :-)
Any ideas please? It may be simple.....may be not! By the way, I believe my web server runs some version of UNIX or Linux - but I could do with it to be fairly cross-platform. I'm not bothered whether it works under Windows really though.....
Thanks a lot!