Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running a Cron Job

Tags:

php

cron

If I have a cron job that run every 10 minutes and for some reason this one time it takes 12 minutes to run the job, will cron start another instance of my code while the previous one is still running? if so how can you prevent this on linux?

like image 657
Tony Borf Avatar asked May 28 '09 18:05

Tony Borf


Video Answer


2 Answers

Yes, it will.

You should make your program create a .pid file (for example in /var/run/). When it starts, it should check if such file already exists and if so exit.

Which program/script are you running?

like image 153
MartinodF Avatar answered Oct 05 '22 09:10

MartinodF


Yes. Cron will fire off a process at the scheduled interval, regardless if a previous one has not completed.

You can touch a file, like stated in another answer, and check for its existence before engaging your process.

Or you could examine the process list to see if an "instance" is already running:

ps -ef | grep *your_script_name* | grep -v grep | wc -l
like image 21
Naum Avatar answered Oct 05 '22 08:10

Naum