This is normal until an unexpected failure occurs (for example, a program crash, a power failure) when a directory exists.
After that, the program will never be launched, because the lock is locked forever (provided that the directory is in a permanent file system).
Normally I would use flock with LOCK_EXCL.
Open the file for reading + writing, creating it if it does not exist. Then take an exclusive lock, if this does not work (if you use LOCK_NB), then another process is blocked.
Once you have a lock, you need to leave the file open.
The advantage of this approach is that if the process dies unexpectedly (for example, a crash, it is destroyed, or the machine fails), the lock is automatically released.
Markr source share