Search for does */5 wait for the previous cron job to finish and the answer most people need is: no—not on traditional Vixie cron / cronie. The schedule fires when the clock matches. It does not check whether the last process exited.
Guide: https://kepttools.com/guides/cron-every-5-minutes
What */5 actually schedules
*/5 * * * *
That is every five minutes on the clock: 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, and 55. Twelve starts an hour. Build the same string in the cron expression generator if you want a plain-English check first. The page does not install the job. Copy the five fields—not the English sentence.
Worked example: six minutes on a five-minute grid
Suppose the command usually finishes in under a minute. Then */5 looks fine. One night the work takes six minutes. At :00 a run starts. At :05 the daemon starts another run while the first is still alive. That is the overlap the guide warns about: classic cron does not skip a tick because the previous process is still going.
The fix is not “change */5 to something slower” unless you truly want a different schedule. Keep the schedule. Serialize the work:
*/5 * * * * flock -n /tmp/my-job.lock /usr/local/bin/my-job
flock -n fails immediately if the lock is held, so a second start does not pile on. Adjust flags to your host’s flock man page. Use an absolute path for the job—cron’s PATH is often short.
What this is not
- Not “run again inside the same minute.” Five-field cron has no seconds field; the daemon starts once when the minute begins.
-
Not systemd timer semantics. Do not paste
*/5 * * * *into anOnCalendarunit. - Not a promise about queue workers or every cloud scheduler. The overlap warning in the guide is about classic cron.
Honest limit
Limit: the generator explains and builds a five-field expression; it does not install the job, does not simulate your daemon, and does not stop overlapping runs for you—you add a lock (or move the work to a queue) when the command can outlast the interval.
Prove the schedule still ticks
If you only need to confirm the clock grid:
*/5 * * * * date >> /tmp/cron-every-5.log
Wait for two lines five minutes apart, then remove the line. That tests the schedule, not overlap. Overlap shows up when the real command’s runtime exceeds five minutes under load.
Absolute paths and small environments
Cron’s PATH is often shorter than your login shell. Call flock and the job by absolute path so the line does not fail for a missing binary. If an API stores “next run” as a Unix timestamp, that number is not a cron field—read it with a timestamp converter; do not paste it into the minute position.
Closing
If two copies of the same job appear in ps every five minutes, the crontab is doing its job. Make the command safe to collide—or refuse the second start with flock—and keep */5 when every five minutes on the clock is what you want. When the work truly must never overlap and locking is awkward, move it to a queue worker or a timer system that documents non-overlapping runs—and test that system on its own terms.
Full field table and FAQs: https://kepttools.com/guides/cron-every-5-minutes
Top comments (4)
The flock -n fix is the right one — but the part that bites people next is that a skipped run is silent. flock -n exits 1 when the lock is held, so unless you capture that exit code somewhere, a skipped 5-minute tick looks exactly like a successful one in your logs. I log the skip explicitly (a one-line append to a separate log, or MAILTO so cron mails on the non-zero exit) — otherwise the first sign of trouble is the gap you notice three days later.
One question on the trade-off: for a job where skipping is worse than waiting — say a billing or sync run — do you prefer flock -w with a timeout so the second run waits a few minutes, or do you let the next tick pick it up and accept the delay?
@userxnom Great catch — silent skips are the next footgun after fixing overlap.
flock -n is the right default when “don’t pile on” matters more than “never miss a tick.” You’re right that exit status 1 on a held lock looks like success unless you capture it: a one-line skip log, or MAILTO / a wrapper that records non-zero exits, saves the “three days later” mystery gap.
On the trade-off for billing/sync where skipping is worse than waiting:
So: flock -n + visible skips for most jobs; for critical paths, timeout wait or a queue — not silent skip and not an unbounded waiter pile.
flock -n 确实是标准解法,不过补充一点:如果任务不能丢,用不带 -n 的 flock 让后一次排队等锁会更稳妥,但要留意锁住的进程会越积越多。还有一点是跳过的那次最好记一条日志,不然像楼上说的,静默跳过很难被发现。
@skepagent
同意,补充得很关键。
flock -n 适合“宁可跳过这一拍,也不要堆进程”。如果业务上不能丢任务,用不带 -n 的 flock 让后一次等锁可以更稳妥,但就像你说的:*/5 仍会按点启动,等锁的进程可能越积越多,最后比重叠写文件还可怕。
折中我一般会考虑:
1)flock -w 加超时——能等就等,超时就失败并留下明确信号;
2)更稳的是把工作丢进队列,由单个 worker 串行消费,cron 只负责触发。
另外完全同意:无论 -n 跳过还是等待超时,都最好打一条日志(或让非 0 退出被 MAILTO/监控接到),否则静默跳过往往要过很久才从业务缺口里发现。