Preventing Overlapping cron Runs
A cron job runs every minute but sometimes takes three minutes, and two copies corrupt each other's output. What is the simplest robust fix?
Choose one answer
Create a file /tmp/running at the start and delete it at the end.
/tmp/running
Wrap it with flock -n /run/lock/myjob.lock so a second copy exits immediately.
flock -n /run/lock/myjob.lock
Check ps aux | grep myjob at the start and exit if found.
ps aux | grep myjob
Use nice -n 19 so the jobs run more slowly and don't overlap.
nice -n 19