in reply to use flock() to determine if other script is running
The semantics for nonblocking flock are to return false if the lock was not obtained, true if it was. If the platform does not support flock a fatal error is thrown.
You are apparantly on a win32ish system, which may or may not support flock, so it would be good to catch the error. See perlport and perlwin32 for details. Try something like this,
For this semaphore system to be effective, the other script should flock the flag file first thing, and drop the lock at the very last, perhaps in a DESTROY() sub.use Fcntl ':flock' ; open ONE, ">> C:\\temp\\RTEOlock.log" or die $!; my $lck = eval {flock ONE, LOCK_EX | LOCK_NB}; die 'flock not supported! ', $@ if $@; if ($lck) { # The other script is not running code here } else { # The other script is running code here }
After Compline,
Zaxo
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
•Re: Re: use flock() to determine if other script is running
by merlyn (Sage) on Aug 21, 2003 at 00:29 UTC | |
by Zaxo (Archbishop) on Aug 21, 2003 at 03:43 UTC | |
|
Re: Re: use flock() to determine if other script is running
by Red_Dragon (Beadle) on Aug 21, 2003 at 15:22 UTC |