Keep crontab jobs from overrunning each other?
If you have开发者_如何转开发 a crontab job that runs every 5 minutes, how do you ensure that it won't ever overrun itself? That is, how do you make sure that the previous iteration of the crontab job completed before the next one runs?
at the beginning of your script, create a unique temp file somewhere in the file system, unless the file already exists, in which case your script is already running and you should exit. at the end of your script, delete the unique temp file.
there are other variations of this i'm sure, but they all have a similar idea. if you like this answer, please select the check mark next to it. thanks!
Use flock. It basically does what dqhendricks suggests.
精彩评论