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?
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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With