Jeff Pang am Dienstag, 7. Februar 2006 10.47:
> hello,lists,
Hello Jeff
> I open a file and obtained a filehandle.then I fork a child and access this
> file in child (via the duplicate filehandle from parent).If both parent and
> child are writting to the file at the same time,the things should become
> terrible.So I should use the 'flock' call to lock the filehandle.But I find
> just in the same process,the flock is effective.In other words,when I flock
> the filehandle in child,the effect of 'flock' mean nothing to parent,and
> parent can still write to the file. the test code is shown as below:
>
> use strict;
> use warnings;
[...]
>
> when this code run,both parent and child can write to the same file,and
> maybe at the same time.
>
> How can I resolve this problem?thanks.

Seems that the flock is implemented as *advisory* lock as stated in
perldoc -f flock
.

The solution lies in the appropriate usage of flock, that means to use locking 
for every access (try) to the resource. Since both accesses are within your 
code, you have 100% control about that :-)

hth,
jo

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to