[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Some confusion with flock.



On Thu, 23 Oct 2025, Tim Woodall wrote:

   exec {FDLOCK}>&-

vs flock -u ${FDLOCK}

I actually managed to get chatGPT to explain this (eventually).

The former closes the file, but doesn't release the lock, the lock is released only when the process exits and the OS determines that it's safe to release the lock.

flock -u unconditionally releases the lock.


Turns out that closing the FD was the old BSD way of doing it and it's still habit in a lot of code where it doesn't matter. It's only cases like mine where the os cleanup gets delayed that the explicit flock -u is now needed.

(Also from chatGPT, so may not be correct!)


Reply to: