From: "siegfried" <[EMAIL PROTECTED]> > 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? >
Hi, Try something like: use File::Pid; my $pid = File::Pid->new(); exit if $pid->running; my $exit; $SIG{INT} = $SIG{BREAK} = $SIG{HUP} = sub {$exit++}; $pid->write() or die "Can't write - $!"; while (!$exit) { #do program } END { $pid->remove() if $pid->pid() == $$; } But if something bad happends like a power off or something like that, the pid file might be left undeleted. The problem of File::PID is that it doesn't delete the pid file if the PID number found inside it is not the pid of a running process. And in that case the program might not start, or start for more times... I don't remember well what happend. But maybe this is not a correct way of using File::PID... Teddy -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>