I'm dealing with issues where my cron jobs are overlapping and accumulating on my Linux servers. For instance, I have a job that runs every 5 minutes, but under heavy load, it can take 7 to 10 minutes to complete. This leads to multiple instances running simultaneously, which causes high CPU usage and timing issues. I've tried things like using lock files, managing timeouts, and breaking up jobs, but it seems like I'm only addressing the symptoms. At what point should I consider moving away from cron jobs altogether? Are there better solutions, like systemd timers or task queues such as Celery or Redis, that provide more control?
5 Answers
The issue might not just be with cron itself, but rather that you’re taking on too much work for the intervals you’ve set. Consider optimizing the scripts or upgrading your server resources. Both improvements could help.
You might need to reevaluate your approach altogether. If your jobs are resource-intensive, consider a more suitable orchestration tool instead of relying solely on cron. There are options out there that might fit your needs better.
Semaphores could be the right route. Your solution should depend on the nature of the tasks: if one job needs to finish before the next starts or if they can wait for the next scheduled time. Logging is also crucial for tracking failures when jobs overlap.
That makes sense! If you need jobs to run without delay, maybe consider changing the intervals for less critical tasks.
A good approach is to check if the script is already running at the beginning. If it is, just skip to the next scheduled run instead of allowing overlapping executions.
That’s what flock does! Instead of modifying every script, just wrap the command with flock in the crontab.
Using lock files within your bash scripts is a simple fix. Just check for the presence of a lock file at the start of your script; if it exists, exit. If not, create it, run your process, and delete the lock file when done.

That’s valid, but even with more resources, overlap becomes a control issue. Cron lacks the ability to properly manage queues.