From: "ara.t.howard" Date: 2008-05-29T08:48:24+09:00 Subject: Re: Ensuring only one instance of a script is running On May 28, 2008, at 4:35 PM, Mike Kasick wrote: > Cute trick. > > However, I wouldn't recommend it's use in any distributed code. > flocks > are intended to serve a purpose other than what's achieved as a side > effect here, and although it's generally safe, the behavior is unknown > at best if the script file resides in a remote file system like NFS. > > For example, in Linux versions prior to 2.6.12 flocks are local > only, so > this would have the intended effect. However, in Linux versions > 2.6.12 > and newer, flocks are emulated by POSIX locks, which should result in > only a single instance running across a set of machines attempting to > run the same script located in an NFS share. you can use the same trick even on NFS require 'posixlock' # gem install posixlock DATA.posixlock( File::LOCK_EX | File::LOCK_NB ) and this will work for both NFS and local fs. of course you'd need to degrade to flock if posixlock is not installed.... my lockfile gem is also NFS safe and can be used for this purpose. actually it can make any program run one instance without modification rlock lockifle run_this_once.rb regards. a @ http://codeforpeople.com/ -- we can deny everything, except that we have the possibility of being better. simply reflect on that. h.h. the 14th dalai lama