home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!ukma!wupost!usc!news!netlabs!lwall
- From: lwall@netlabs.com (Larry Wall)
- Newsgroups: comp.lang.perl
- Subject: Re: open(lockfile, O_CREAT|O_WRONLY|O_EXCL, 0444) in perl?
- Keywords: lock file
- Message-ID: <1992Aug19.173104.22684@netlabs.com>
- Date: 19 Aug 92 17:31:04 GMT
- References: <1992Aug19.082244.61337@ilx018.intel.com>
- Sender: news@netlabs.com
- Organization: NetLabs, Inc.
- Lines: 21
- Nntp-Posting-Host: scalpel.netlabs.com
-
- In article <1992Aug19.082244.61337@ilx018.intel.com> steed@ilws14 (Ze'ev Shtadler) writes:
- : I'd like to have a perl script that uses a lock file as a semaphore
- : across NFS of diverse hardware platforms and operating systems. I was
- : told, this is the only "real safe" way to ensure exclusive access
- : between processes on different machines (I know this does not apply to
- : processes not bothering to lock :-). Can that be done from within
- : perl?
-
- Certainly.
-
- open(MYFILE,">$LOCKDIR/LOCK.$$"); print MYFILE $$,"\n"; close MYFILE;
- while (!link("$LOCKDIR/LOCK.$$", "$LOCKDIR/LOCK")) {
- print "WAITING FOR THE STUPID LOCK!!!!!\n";
- sleep 17;
- }
-
- ...
-
- unlink "$LOCKDIR/LOCK.$$", "$LOCKDIR/LOCK";
-
- Larry
-