On 27 Dec 2000, at 10:11, Mark Murray wrote:

> > Any ideas on how to do this?  Any suggestions on the process?
> 
> Simple lock (like flock(3)) in the perl script. Lock some ${FILE},
> and if you can't get the lock, die. The file should contain the PID
> of the process that holds the lock, so that a cleanerd can kill
> stuck processes, or so that the lock can be blown away if needed.
> 
> Works like a charm.

Mark and I have been msging offline and he's agreed to my posting the 
results of our discussion:

> > > > Thanks Mark.  But what part of the solution does flock solve?
> > > 
> > > It prevents more than one perl script from running. You can then 
> > > cron perl scripts to deal with the incoming, and not worry about
> > > them jumping on each other. 
> > 
> > Yes.  That does make some things much easier.  That's a very
> > simple solution.
> > 
> > I was looking for a gold-plated solution where messages are 
> > processed right away.  But it sounds too complicated.  I guess 
> > setting up a cron job to run every minute is fine.  
> > 
> > The perl script looks like this:
> > 
> > flock a file, if it fails, die.
> 
> Write PID to flocked file.
> 
> > Loop
> >   Get oldest file in directory (file are named Y.m.d.h.m.s.PID)
> >   process it
> >   move file to archives
> > until no more files
> 
> Truncate file
> 
> > unlock the file
> > 
> > The cleaner you mentioned: run it every 15 minutes, compare the 
> > date/time on the lockfile, if more than 15 minutes old, grab the PID,  
> > and kill the job, remove the lock.
> 
> Correct.

Thanks Mark.

--
Dan Langille
The FreeBSD Diary - http://freebsddiary.org/
       FreshPorts - http://freshports.org/
     NZ Broadband - http://unixathome.org/broadband/


To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message

Reply via email to