Verified Jobs Live
Unix / Linux Medium Level ~3 min read

How would you schedule a recurring Linux job so two runs do not overlap?

Interactive Practice Mode
Formulate your thoughts or take notes before revealing the model solution.
Model Answer & Deep-Dive Explanation

Use an appropriate locking mechanism around the entire protected job, such as flock on a lock file in a directory accessible to the job’s user. Decide whether a second invocation should wait or exit and ensure the lock scope covers all relevant work. Use explicit paths, a controlled environment, reliable logging, and meaningful exit codes. A scheduler interval alone does not prevent overlap when a run lasts longer than expected. File locking on one host is not a distributed lock, and filesystem semantics must be suitable for the chosen mechanism.