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: | Scottrudy |
---|---|
Location: | Fremont, CA |
Users: | 2 |
Nodes: | 10 (0 / 10) |
Uptime: | 42:35:50 |
Calls: | 42 |
Messages: | 23,040 |