Programming Wiki: Perl: Writing to a file with a lock file

Programming Wiki : PerlWritingToFile

WikiHomePage :: Categories :: PageIndex :: RecentChanges :: RecentlyCommented :: Login/Register
Oldest known version of this page was edited on 2006-04-16 21:08:59 by ScottRippee []
Page view:

Perl: Writing to a file with a lock file

Perl


# create a lock file
$lockfile="lock_the_file.loc";
while (-e $lockfile) {
 sleep 2;
}
open (LOCK,">$lockfile") || die ("Cannot open lock file!\n");
close (LOCK);

# write to the data file
open(FOUT,">$myfile") || die("Cannot Open File");
print FOUT "String to put in file\n";
close(FOUT);

# delete the lock file
unlink($lockfile);
Powered by Wikka Wakka Wiki 1.1.6.0
Page was generated in 0.0279 seconds