Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Perl Beginners Cgi > Re: file lock u...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 4 Topic 1391 of 1496
Post > Topic >>

Re: file lock unnecessary?

by greg@[EMAIL PROTECTED] (Greg Jetter) Apr 25, 2007 at 06:31 AM

On Wednesday April 25 2007 6:14 am, Varj=C3=BC Tam=C3=A1s wrote:
> Hello everyone!
>
> I have written a perl script which opens a file for reading and writing.
> I tested what happens if the script is run in multiple instances by the
> webserver.  I put a sleep command between seeking writing position in
> the file and actual writing.  I filled the web form in two different
> tabs of my browser and sent it.
>
> My impression was that the following happens:
> - first instance opens the file,
> - first instance seeks the writing position,
> - first instance goes sleeping,
> - second instance opens the same file,
> - second instance seeks the writing position (different from the above
> one),
> - second instance goes sleeping,
> - first instance wakes up,
> - first instance writes the file,
> - first instance closes the file,
> - second instance wakes up,
> - second instance writes the file,
> - second instance closes the file.
>
> After that procedure both changes has appeared in the file.
>
> Does it mean, that on this system the multiple instance writing of a
> file is handled well and I do not have to worry about locking the file
> as long as the different instances write different positions in the
> file?  Even the system administrator had the tip, that only the last
> change will appear.
>
> If I want to be sure that multiple instance writing will work, is append
> a better choice?  I have read that on the archive of this list.
>
> Thanks

you should use flock to  lock the file , so one process can work on it at
a=
=20
time , if you don't eventually  a race way condition will occur  and 
you=20
will see a lock up happen , or   if your luck  one process will 
overwrite=
=20
the other  and you will just loose data..  either way  it's  just smart=20
programming to lock a file  your working on especially if  it's
happening=20
under CGI conditions.

Greg
 




 4 Posts in Topic:
file lock unnecessary?
kanya@[EMAIL PROTECTED]   2007-04-25 16:14:40 
Re: file lock unnecessary?
greg@[EMAIL PROTECTED] (  2007-04-25 06:31:16 
Re: file lock unnecessary?
kanya@[EMAIL PROTECTED]   2007-04-25 18:42:17 
Re: file lock unnecessary?
greg@[EMAIL PROTECTED] (  2007-04-25 09:14:25 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Nov 22 11:52:43 CST 2008.