Linux – Queue’ing cron jobs up to 10 times

cronlinuxPHP

This kind of touches on another post I made but is different so I have posted it as a new question.

I have a script that runs that may take just over 1 minute to process, and my cron is set to run every minute. I can stop another cron job executing the script if the first one hasn't finished by using flock (php) in the file, however, this means that I would lose one iteration of the routine and have to wait nearly a minute before it is triggered again (as my understanding leads me to believe).

What I would like to do is if the script is locked, not bomb out, but wait. Over time however, this could get quite high so I would also like to limit the amount of queued cron's to 10.

I am a real newbie with Linux (had a Linux VPS for 3 days now) so I am not sure if my solution is even practical.

Thanks.

Best Answer

I would say that each job could create a lock file and wait on the newest existing lock file. If the count of lock files is 10, then exit instead of creating and waiting.