home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / perl / 5388 < prev    next >
Encoding:
Internet Message Format  |  1992-08-19  |  1.1 KB

  1. Path: sparky!uunet!ukma!wupost!usc!news!netlabs!lwall
  2. From: lwall@netlabs.com (Larry Wall)
  3. Newsgroups: comp.lang.perl
  4. Subject: Re: open(lockfile, O_CREAT|O_WRONLY|O_EXCL, 0444) in perl?
  5. Keywords: lock file
  6. Message-ID: <1992Aug19.173104.22684@netlabs.com>
  7. Date: 19 Aug 92 17:31:04 GMT
  8. References: <1992Aug19.082244.61337@ilx018.intel.com>
  9. Sender: news@netlabs.com
  10. Organization: NetLabs, Inc.
  11. Lines: 21
  12. Nntp-Posting-Host: scalpel.netlabs.com
  13.  
  14. In article <1992Aug19.082244.61337@ilx018.intel.com> steed@ilws14 (Ze'ev Shtadler) writes:
  15. : I'd like to have a perl script that uses a lock file as a semaphore
  16. : across NFS of diverse hardware platforms and operating systems.  I was
  17. : told, this is the only "real safe" way to ensure exclusive access
  18. : between processes on different machines (I know this does not apply to
  19. : processes not bothering to lock :-).  Can that be done from within
  20. : perl?
  21.  
  22. Certainly.
  23.  
  24.     open(MYFILE,">$LOCKDIR/LOCK.$$"); print MYFILE $$,"\n"; close MYFILE;
  25.     while (!link("$LOCKDIR/LOCK.$$", "$LOCKDIR/LOCK")) {
  26.     print "WAITING FOR THE STUPID LOCK!!!!!\n";
  27.     sleep 17;
  28.     }
  29.  
  30.     ...
  31.  
  32.     unlink "$LOCKDIR/LOCK.$$", "$LOCKDIR/LOCK";
  33.  
  34. Larry
  35.