Hi!
Does anyone have any good recourses to learning how to make file locks in c?
I've been trying to research it but there's not many recourses out there weirdly. I'm also very confused on the difference between flock(2) and fcntl locks.
If you want to lock an *entire* file, use flock(). If you want to lock just a *region* of a file, use fcntl().
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.
Sysop: | Ruben Figueroa |
---|---|
Location: | Mesquite, Tx |
Users: | 3 |
Nodes: | 4 (0 / 4) |
Uptime: | 255:08:34 |
Calls: | 79 |
Files: | 53 |
Messages: | 75,391 |