---
title: "How to stop overlapping cron job runs"
url: "https://cronmissed.com/learn/overlapping-cron-runs.md"
canonical_url: "https://cronmissed.com/learn/overlapping-cron-runs"
last_updated: "2026-10-22"
type: "conceptual"
summary: "A cron job that outlasts its interval starts a second copy. See how to prevent overlaps with flock and the controls in each scheduler."
related: ["https://cronmissed.com/learn.md", "https://cronmissed.com/learn/start-and-finish-pings.md", "https://cronmissed.com/guides/kubernetes-cronjob.md", "https://cronmissed.com/guides/node-cron.md", "https://cronmissed.com/guides/apscheduler.md"]
---

# How to stop overlapping cron job runs

> **For AI agents:** the complete index of CronMissed pages is [llms.txt](https://cronmissed.com/llms.txt). Every page is also served as markdown at its URL plus .md.

A cron job that outlasts its interval starts a second copy. See how to prevent overlaps with flock and the controls in each scheduler.

Cron starts a job on schedule whether the last run has finished or not. A job that takes longer than its interval runs twice at once, and two copies of a backup or an import can corrupt data. Take a lock at the start, and let the scheduler skip or queue the late run.

## How do I lock a shell job?

```crontab
*/5 * * * * flock -n /var/lock/import.lock /usr/local/bin/import.sh && curl -fsS --retry 5 https://ping.cronmissed.com/5f0c1b2e-7a3d-4c8e-9b61-2d4f8a7e3c10
```

`flock -n` takes the lock or exits at once with a non-zero status when another copy holds it. Because of the `&&`, a skipped run sends no ping, which is the honest result. If skipped runs are normal, send `/log` instead of nothing, so you can see them.

## What does each scheduler offer?

| Scheduler | Control | What a late run does |
| --- | --- | --- |
| Kubernetes CronJob | concurrencyPolicy: Allow, Forbid or Replace | Forbid counts the skipped schedule as missed |
| Laravel | withoutOverlapping() | Skipped while the lock is held; the lock expires after 24 hours by default |
| node-cron | noOverlap: true | The tick is skipped |
| APScheduler | max_instances, one by default | Counted as a misfire |
| pg_cron | One instance per job | A second run is queued and starts when the first ends |
| Render | Single-run guarantee | The next scheduled run waits for the active run |
| Railway | No termination of active runs | The new run is skipped |
| Vercel Cron | None built in | A second invocation can start while the first runs; use a lock |

## How does monitoring help?

A skipped or queued run is a late run, so a check with a start ping sees it either way. If a job regularly outlasts its interval, the start pings show a pattern: runs that begin late, or that never finish before the next begins. Raise the interval or fix the job, and set the grace for the real run time. See [start and finish pings](https://cronmissed.com/learn/start-and-finish-pings.md).

## Questions

### Is overlapping always a problem?

No. Idempotent jobs, such as a refresh that can be run any number of times, may overlap harmlessly. Jobs that write, move or delete data usually must not.

### Why use a lock file and not check for the process?

A lock held by the kernel disappears when the process dies, so a crash cannot leave a stale lock. A pid file or a ps check can be fooled by a recycled pid or a race.

## Sources

- [Kubernetes documentation: CronJob](https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/), read 22 October 2026
- [Laravel documentation: task scheduling](https://laravel.com/docs/13.x/scheduling), read 22 October 2026
- [Render Docs: cron jobs](https://render.com/docs/cronjobs), read 22 October 2026
- [Railway Docs: cron jobs](https://docs.railway.com/reference/cron-jobs), read 22 October 2026

## Related pages

- [Start and finish pings](https://cronmissed.com/learn/start-and-finish-pings.md)
- [Kubernetes CronJobs](https://cronmissed.com/guides/kubernetes-cronjob.md)
- [node-cron](https://cronmissed.com/guides/node-cron.md)
- [APScheduler](https://cronmissed.com/guides/apscheduler.md)

## Related

- [Cron monitoring explained: concepts and fixes](https://cronmissed.com/learn.md)
- [Start and finish pings for long-running jobs](https://cronmissed.com/learn/start-and-finish-pings.md)
- [Kubernetes CronJob schedule: monitor every run](https://cronmissed.com/guides/kubernetes-cronjob.md)
- [Monitor node-cron scheduled tasks](https://cronmissed.com/guides/node-cron.md)
- [APScheduler cron jobs: schedule and monitor](https://cronmissed.com/guides/apscheduler.md)
