On Fri, 2006-21-04 at 14:48 -0400, Lewis, Cory (Genworth) wrote:
> 
> > I have a cron job running perl and it is taking a very long time --
> > sometimes over 24 hours.
> > 
> > How can I have cron schedule my job daily, or even hourly, 
> > and have the perl
> > code  exit if a previouse instance of the job is still running?
> > 
> > Some have suggested creating a file in /tmp and checking it before
> > proceding. But what if a cron job exits prematurely, perhaps 
> > because of a
> > division by zero, and does not delete the /tmp file?
> > 
> > How do I set up a signal handler to gaurentee that the 
> > /tmp/do_not_run_yet
> > file gets deleted when the cron job exits?
> > 
> 
> 
>  I've not done it with perl, but we have several other scripts that have
> this issue. We have the scripts output a file with it's PID. And anytime
> the script starts it looks for that file and the PID. If it finds it, it
> checks to see if the PID is still active - if it is, it exits, otherwise
> it keeps running and updates the file with the new PID.
> 
> Cory

If the PID is active and it matches a process of similar name already
running, usually by checking /proc or /var/proc (see `man 5 proc). And
then it sends a semaphore (see `man 5 ipc`) or a SIGUSR1 (see `man 7
signal`) to determine if it's not hung.

Of course there other way is to stick in a /etc/rc?.d/* file and let
init (see `man 8 init`) take care of everything.


-- 
__END__

Just my 0.00000002 million dollars worth,
   --- Shawn

"For the things we have to learn before we can do them, we learn by doing them."
  Aristotle

* Perl tutorials at http://perlmonks.org/?node=Tutorials
* A searchable perldoc is at http://perldoc.perl.org/



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to