http://qs1969.pair.com?node_id=410760

johnnywang has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I'm trying to make sure that multiple processes (not threads) access a common resource in a sequential fashion. My simple solution is to gain a lock on a file, like:
open(FH, ">>lock.txt") or die "can't open lock.txt: $!\n"; flock(FH, 2) or die "Can't flock lock.txt: $!\n"; now_access_the_common_resource(); close(FH);
This seems to work fine. I'm wondering whether this is the most common practice, and whether there are "better" methods,or a simple module that does this. Thanks.