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: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 376 |
Nodes: | 16 (2 / 14) |
Uptime: | 14:19:44 |
Calls: | 8,017 |
Calls today: | 7 |
Files: | 13,028 |
Messages: | 5,822,750 |