Re: massive confusion on file locks
By: candycane to Digital Man on Thu Aug 10 2023 02:36 pm
Re: massive confusion on file locks
By: Digital Man to candycane on Thu Aug 10 2023 09:30 am
If you want to lock an *entire* file, use flock(). If you want to lock just a *region* of a file, use fcntl().
So, whats the difference between LOCK_EX and SH? and does trying to obtain a lock already held suspend the program?
Yes, that is what is meant by this line from the man page for flock():
A call to flock() may block if an incompatible lock is held by another process. To make a nonblocking request, include
LOCK_NB (by ORing) with any of the above operations.
So by default, yes, it'll suspend the program if the file is already locked with an incompatible lock from what is being attempted.
For more details, see "man 2 flock" or
https://linux.die.net/man/2/flock
--
digital man (rob)
Sling Blade quote #5:
Karl Childers (to father): You ought not killed my little brother...
Norco, CA WX: 76.2°F, 66.0% humidity, 0 mph SSW wind, 0.00 inches rain/24hrs ---
■ Synchronet ■ Vertrauen ■ Home of Synchronet ■ [vert/cvs/bbs].synchro.net