[CentOS] Re: Any one have a good example...

Tue Aug 29 19:08:35 UTC 2006
Scott Silva <ssilva at sgvwater.com>

James Olin Oden spake the following on 8/29/2006 11:48 AM:
> Actually if you use a language that supports flock() do the following:
> 
>   Create lock file at installation of the script.
>   In script call flock(2) in a non-blocking manner against this file.
>   If you don't aquire the lock then exit with suitable message.
>   If you do get the lock do your stuff and exit.
> 
> Locks aquired by flock automatically go away when the file handle is
> closed (and the filehandle automatically gets closed like or not after
> you exit a proccess...also in various languages scoping will also
> apply).
> 
> This is easily done in perl (man perlfunc and look up flock()), and if
> your comfortable in C its pretty trivial create said wrapper.
> 
> The key is the file must pre-exist before your script is ever called,
> because there is a race condition on creating the file, but you
> guarantee the files pre-existance the race condition is removed.
> Typically I would make the "lock" file owned by the package that
> delivers the software.  No fuss, no muss.
> 
> Good luck...james
> 
> On 8/29/06, Scott Silva <ssilva at sgvwater.com>
> wrote:
>> ...of a shell script for rsync that won't start again if it is already
>> running?
>> I thought of using a lock file, but what if it is killed mid script or
>> bombs?
I was hoping to throw this together in bash, but I guess I'll dig out my perl
book. I need some practice anyways.


-- 

MailScanner is like deodorant...
You hope everybody uses it, and
you notice quickly if they don't!!!!