|
|
 |
 |
 |
 |
Perl Programming Language
|
 |
 |
 |
 |
 |
 |
 |
 |
Need suggestions on a good locking module
I have a script that I want to run, but only one instance. So I want to set up crontab to start it every minute, but if it is already running, I would exit. I looked at LockFile::Simple but I do not like it. I want to find a module that opens a file with O_EXCL and uses that for locking. (local hard drive filesystem only) I know that I could just use sysopen, but I am hoping that perhaps a well debugged module would clean some gotchas that I did not think about. thanks i
On Jun 4, 8:33 am, Ignoramus27175 <ignoramus27...@NOSPAM. 27175.invalid> wrote: > I have a script that I want to run, but only one instance. So I want > to set up crontab to start it every minute, but if it is already > running, I would exit. > I looked at LockFile::Simple but I do not like it. I want to find a > module that opens a file with O_EXCL and uses that for locking. (local > hard drive filesystem only)
At the start of the program create a file if it does not exist and at the end delete a file. If the file exists, then exit program. HTH Dinakar Desai
In article <MP6dndxNyasrifnbnZ2dnUVZ_v-tn@giganews.com>, ignoramus27@NOSPAM.27175.invalid says... >I have a script that I want to run, but only one instance. So I want >to set up crontab to start it every minute, but if it is already >running, I would exit. >I looked at LockFile::Simple but I do not like it. I want to find a >module that opens a file with O_EXCL and uses that for locking. (local >hard drive filesystem only) >I know that I could just use sysopen, but I am hoping that perhaps a >well debugged module would clean some gotchas that I did not think >about.
Look at Proc::PID::File cheers Heinrich -- Heinrich Mislik Zentraler Informatikdienst der Universitaet Wien A-1010 Wien, Universitaetsstrasse 7 Tel.: (+43 1) 4277-14056, Fax: (+43 1) 4277-9140
On Jun 5, 4:23 am, Heinrich.Mis@univie.ac.at (Heinrich Mislik) wrote: > In article <MP6dndxNyasrifnbnZ2dnUVZ_v-tn @giganews.com>, ignoramus27 @NOSPAM.27175.invalid says... > >I have a script that I want to run, but only one instance. So I want > >to set up crontab to start it every minute, but if it is already > >running, I would exit. > Look at Proc::PID::File
Theres also File::Pid. A (very) quick glance at the source for both leads me to believe File::Pid is cleaner. Looks like Proc::PID::File isnt portable (uses ps in backticks). File::Pid uses perl's kill(). Anyone got any opinions on which is better? Todd W.
des @gmail.com wrote: >At the start of the program create a file if it does not exist and at >the end delete a file. If the file exists, then exit program. And what if the program crashes or gets interrupted? That way, the lockfile would never be deleted. And you have a race condition, between testing if the file exists, and actually creating it (unless you're openign the file with the O_EXCL flag (from Fcntl), which somehow I doubt.) (see http://bama.ua.edu/cgi-bin/man-cgi?open+2) -- Bart.
On Tue, 05 Jun 2007 20:39:09 -0000, trwww <waveri @gmail.com> wrote: > On Jun 5, 4:23 am, Heinrich.Mis @univie.ac.at (Heinrich Mislik) > wrote: >> In article <MP6dndxNyasrifnbnZ2dnUVZ_v-tn @giganews.com>, ignoramus27 @NOSPAM.27175.invalid says... >> >I have a script that I want to run, but only one instance. So I want >> >to set up crontab to start it every minute, but if it is already >> >running, I would exit. >> Look at Proc::PID::File > Theres also File::Pid. A (very) quick glance at the source for both > leads me to believe File::Pid is cleaner. > Looks like Proc::PID::File isnt portable (uses ps in backticks). > File::Pid uses perl's kill(). > Anyone got any opinions on which is better? > Todd W.
I like this module a lot. What I discovered is that there is a program called "lockfile" (I believe, part of procmail package) that does what I want. So, my crontab entries look like this: */5 04-18 * * * if lockfile -r 1 /tmp/WatchDog.lock ; then $HOME/smile/support/WatchDog.pl; rm /tmp/WatchDog.lock ; fi > ~/log/watchdog.log 2>&1 This means that every 5 minutes I check the lock, and if it is available, it gets locked and my process runs. in /etc/rc.d/rc.local I remove these locks when I boot. i
|
 |
 |
 |
 |
|