Skip to content

.tip

· one of the small things

flock -n keeps a cron job from overlapping itself

An entry that runs every five minutes and a job that occasionally takes seven leaves two copies working the same rows, and from there the runs pile up until something times out.

*/5 * * * * flock -n /var/lock/sync-orders.lock sync-orders

-n gives up immediately with exit status 1 instead of queueing behind the run already holding the lock. The kernel releases it when that process dies, so a crash or a kill -9 leaves nothing stale to clear by hand. Use -w 30 instead when waiting a little beats skipping the run.

shelloperationsconcurrency