Fix: Adding flock Safety to Cron Jobs

flock is a Linux utility that acquires a file-based lock before running a command. It prevents a new invocation from starting if the previous one is still running.

flock syntax patterns
# Non-blocking (skip if running):
*/5 * * * * flock -n /tmp/jobname.lock /path/to/script.sh

# Wait up to 10 seconds then skip:
*/5 * * * * flock -w 10 /tmp/jobname.lock /path/to/script.sh

# With inline command:
*/5 * * * * flock -n /tmp/sync.lock bash -c 'cd /app && node sync.js'

Use a unique lock file per job. /tmp/ is cleared on reboot, so stale locks from crashed processes are automatically removed.

Convert all jobs at once

The ConfigClarity Cron Visualiser has a flock safety toggle — enable it to generate flock-wrapped versions of all your jobs with unique lock file names automatically.

Toggle flock safety on in the Cron Visualiser to wrap all your jobs.

Open Tool →

Related Glossary Terms