What happens when a cron job takes longer than its interval
We ran jobs longer than their interval under cron, cronie, systemd timers, supervisord and RunWisp. cron stacks copies; systemd runs them back to back.
10 min read
The job was * * * * * and took twenty seconds. The table it reads has grown since, and now it
takes two and a half minutes. Nobody changed the schedule. What does the scheduler do at the next
minute, while the last run is still going?
Each scheduler has a different answer, and most of them don’t tell you which one you got. We tested five on the same job and wrote down what they did.
supervisorctl start when the program is already runningShort answer
- cron (Debian’s cron, cronie, anything Vixie-derived) starts another copy on top. A job that takes 2.5 times its interval runs three copies at once, indefinitely. Nothing is logged about it.
- A systemd timer never runs two copies of a unit. It doesn’t skip the late run either: as soon as
the old run ends, it starts the service again, folding every missed time into that one run. A job
that’s always too slow runs back-to-back with no gap.
DeferReactivation=true(systemd 257+) makes it wait for the next slot instead. - supervisord isn’t a scheduler. If cron drives it with
supervisorctl start, a start while the program runs printsERROR (already started)and exits0, so it’s a silent skip. - RunWisp, an open-source cron replacement that ships as a single binary, queues the late run by default and can skip or kill instead, per task. Skipped and killed runs show up in the run history.
| Scheduler | Next tick, while the last run is going | When that run ends | Leaves a record |
|---|---|---|---|
| cron, cronie | starts another copy | nothing special | no |
| systemd timer | nothing | starts again immediately, once | no |
…with DeferReactivation=true |
nothing | waits for the next calendar time | no |
supervisord + supervisorctl |
ERROR (already started), exit 0 |
nothing special | no |
RunWisp, on_overlap = "queue" |
waits in a queue (up to 100) | starts the next queued run | yes, as pending |
RunWisp, on_overlap = "skip" |
dropped | runs at the next tick | yes, as skipped |
RunWisp, on_overlap = "kill" |
stops the old run, starts the new one | n/a | yes, as stopped |
How we tested
The same shell script everywhere: write a start line with the PID and time, sleep, write an end
line. cron and supervisord ran in containers: Debian 13 with cron 3.0pl1-197 and supervisor
4.2.5, and Fedora 43 with cronie 1.7.2. The cron job was * * * * * and slept 150 seconds.
systemd 259 ran user timers every 20 seconds (OnCalendar=*:*:00/20, AccuracySec=1s) for a job
that slept 75. RunWisp 1.9.2 ran @every 20s with a 50-second job.
cron: another copy, every time
cron checks the time once a minute and starts every line that matches. It has no idea the previous run of the same line is still going; it doesn’t track that at all. Two minutes into the test, Debian’s cron had three copies running:
$ ps -eo pid,etimes,args | grep '[j]ob cron'
22 123 /bin/sh /usr/local/bin/job cron
28 63 /bin/sh /usr/local/bin/job cron
35 3 /bin/sh /usr/local/bin/job cron
cronie on Fedora did exactly the same. Each run finished 150 seconds after it started, so the count settled at three and stayed there. A job that takes ten times its interval would settle at ten, and if it is slow because of load, the extra copies add load and it doesn’t settle at all.
The cron log gets an ordinary CMD line for each start. Nothing says the previous run was still
going.
The usual fix is flock in front of the command, which makes a run skip (-n) or wait (-w) while
another holds the lock. That has its own post, with the three
gotchas that come with it.
systemd timers: no overlap, no gap either
The systemd.timer man page
says it plainly:
Note that in case the unit to activate is already active at the time the timer elapses it is not restarted, but simply left running. There is no concept of spawning new service instances in this case.
That’s the part everyone quotes. What it doesn’t say there is what happens next. Here’s the journal for a 75-second job on a 20-second timer (unit renamed, host trimmed):
$ journalctl --user -u job.service -o short-precise
16:09:20.180 systemd[2158]: Starting job.service...
16:09:20.196 job[1148594]: start pid=1148594 16:09:20
16:10:35.199 job[1148594]: end pid=1148594 16:10:35
16:10:35.199 systemd[2158]: Finished job.service.
16:10:35.200 systemd[2158]: Starting job.service...
16:10:35.209 job[1151961]: start pid=1151961 16:10:35
16:11:50.212 job[1151961]: end pid=1151961 16:11:50
16:11:50.213 systemd[2158]: Finished job.service.
16:11:50.214 systemd[2158]: Starting job.service...
The times 16:09:40, 16:10:00 and 16:10:20 came and went with no log line. Then the run ended at 16:10:35 and the next one started in the same millisecond, not at 16:10:40.
The reason is in how the timer picks its next time. While the service runs, the timer is waiting
for it and has no next time at all (systemctl list-timers shows NEXT as -). When the service
stops, the timer computes the next calendar time after its last trigger, 16:09:20. That’s 16:09:40,
already in the past, so it fires at once. However many times were missed, you get one extra run.
We got the same result with Type=oneshot and Type=exec, and with a monotonic
OnUnitActiveSec=20s timer instead of OnCalendar=. So a systemd timer behaves like a queue that
holds one run. For most jobs that’s a sensible default: nothing overlaps, and the work the missed
ticks would have done happens once, as soon as it can. For a job that is always slower than its
interval, it means the job never stops. It runs back-to-back, the timer looks healthy, and the
journal has no line that says “late”.
Waiting for the next slot instead
systemd 257 added DeferReactivation= for exactly this. With it, the timer computes the next time
from when the service finished:
[Timer]
OnCalendar=*:*:00/20
DeferReactivation=true
Same 75-second job: it finished at 16:13:15 and the next run started at 16:13:20, the next
calendar slot. It only works with OnCalendar=. Debian 13 ships systemd 257, so it has it; Debian
12 (252) and Ubuntu 24.04 (255) don’t, and older versions log the key as unknown and ignore it.
Starting it by hand while it runs
systemctl start on a service that’s already running doesn’t start a second copy either, but how
it says so depends on the type:
Type=oneshot: the service is stillactivatingwhile the job runs, so yourstartjoins the job already in progress and blocks until the run finishes. Ourtimeout 10 systemctl startwas still waiting when it gave up. Remember this before you put asystemctl startin a deploy script.Type=execorsimple: the service isactive, sostartreturns0immediately and does nothing.systemctl restartstops the running copy and starts a new one: the “kill the old run” policy.
Two more things that come up here. A service with RemainAfterExit=yes stays active after its
process exits, so a repeating timer starts it once and then never again. And if you actually
want copies in parallel, you need a template unit ([email protected]), because each instance is a
separate unit.
supervisord: not a scheduler, but people schedule with it
supervisord keeps programs running; it has no clock. It still ends up running periodic jobs in two ways.
The loop. command=sh -c 'while true; do /usr/local/bin/job; sleep 60; done' with
autorestart=true. This can’t overlap, since there’s only ever one process, but the interval is
“60 seconds after the last run ended”, not “every minute”. It drifts by the job’s runtime, and
supervisord has no record of individual runs, only one long-running process.
cron calling supervisorctl start. The program is defined with autostart=false and
autorestart=false, and a crontab line starts it. This is where it gets quiet:
$ supervisorctl start job; echo "rc=$?"
job: started
rc=0
$ supervisorctl start job; echo "rc=$?"
job: ERROR (already started)
rc=0
The second start is a skip, which is probably what you want, but it exits 0, and supervisord
doesn’t log the attempt. That’s deliberate: in
supervisorctl.py
do_start excludes ALREADY_STARTED when it sets the exit status. Your cron line can’t tell a
start from a skip. If it matters, check supervisorctl status job first.
Two traps in this setup:
startsecsdefaults to 1. A job that finishes in under a second is markedFATAL Exited too quickly, andsupervisorctl startexits7. Setstartsecs=0for run-to-completion programs.supervisorctl restartcan leave the old work running. It sendsSIGTERMto the program’s process only. Our job was a shell script runningsleep, and after a restart the oldsleepwas still there with parent PID 1, next to the new copy. Setstopasgroup=true(it implieskillasgroup) so the whole process group gets the signal.
numprocs=2 gives you deliberate parallel copies (pool:pool_0, pool:pool_1), each started and
tracked separately.
RunWisp: pick a policy per task
RunWisp, our project, is an open-source cron replacement that ships as a single binary. It runs one
copy of each task at a time (max_concurrent = 1), and on_overlap decides what happens to a run
that arrives while that copy is busy:
[tasks.report]
cron = "* * * * *"
run = "/usr/local/bin/report"
on_overlap = "skip" # "queue" (default), "skip" or "kill"
We ran all three side by side, @every 20s with a 50-second job:
| Policy | What happened |
|---|---|
queue |
each tick added a pending run; each started the moment the one before it ended. After 80 s, 3 were waiting |
skip |
ticks during a run were recorded as skipped (exit -1); the next run started at the first tick after |
kill |
each tick stopped the running copy after 20 s (stopped, exit -1) and started a new one |
All of them leave a row in the run history, so a task that has started overlapping is visible without reading logs. They have downsides too:
queuebuilds a backlog when the job is always slower than its schedule. The queue holds 100 runs by default (max_queued). After that, new runs are dropped and recorded asqueue_full.killnever finishes a job that always takes longer than its interval. It’s meant for jobs where only the newest run matters, like a rebuild.skiploses runs. They’re recorded, but they don’t happen.
If you want systemd’s behaviour, set max_queued = 1: one late run waits and starts as soon as the
current run ends, and the ticks after it are recorded as queue_full instead of disappearing.
All of this is per task and per machine. It doesn’t stop two different tasks from fighting over the same database or backup repository, and two RunWisp daemons on two servers don’t share it. The details are in the overlapping runs docs.
Which behaviour you want
- A probe, a poll, a cache refresh: skip. The next run does the same work.
flock -n -E 0under cron,on_overlap = "skip"in RunWisp, orDeferReactivation=trueon a timer. - Each run handles its own batch: queue, but keep the queue short and look at why it’s growing. A systemd timer’s one-run catch-up is often enough.
- A rebuild or a deploy where only the latest matters: kill and replace.
systemctl restart, oron_overlap = "kill". - Never: plain cron’s default of running them all at once, unless the job really is safe to run in parallel and you’ve checked.
Whichever you pick, a job that keeps overlapping is telling you something. It has outgrown its schedule: the input grew, a query lost its index, an API got slower. Log how long each run takes, then either make it faster or run it less often. A timeout stops one stuck run from blocking every run after it.
Related: stopping a cron job from running twice with flock,
what happens when the scheduler itself is killed,
and missed runs after shutdown or suspend. RunWisp’s
source is on GitHub.
Common questions
What happens if a cron job takes longer than its interval?
Does a systemd timer start the service again if it is still running?
Why does my systemd timer run the service again right after it finishes?
Why does supervisorctl start say ERROR (already started) but exit 0?
Is there a scheduler that records runs skipped because the last one was still going?
Read next
-
PM2 cron_restart runs the script immediately: how to stop it
pm2 start --cron runs your job the moment you start it and again on every reload. We tested PM2 7.1.2 and found three ways to run it only at the cron time.
-
Cron MAILTO not working? Where cron's email actually goes
We sent cron mail on Debian, Ubuntu, Fedora and Alpine and traced where it went: /var/mail, syslog, a refused port 25 or nowhere. Then made msmtp deliver it.