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: | MarisaG |
---|---|
Location: | South San Francisco, CA |
Users: | 81 |
Nodes: | 15 (0 / 15) |
Uptime: | 154:23:33 |
Calls: | 1,431 |
Calls today: | 1 |
Files: | 7 |
Messages: | 22,129 |