3 ms·
flock locks are released when the file is no longer open. This means that no matter how your command exits the OS will close open files and release the lock for
by nickcw 5y ago
flock locks are released when the file is no longer open. This means that no matter how your command exits the OS will close open files and release the lock for you.
The problem with creating files is that you then have the stale lock file problem to deal with which adds a lot more complication.
- the2ndfloorguy 5y agoIs there any other way without using lock files? Using socket or something?
- tyingq 5y agoI suppose you could try listening on a socket at a specific port. The next process would get EADDRINUSE if you were still running. There's also sysv or posix semaphores.