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: | digital man |
---|---|
Location: | Riverside County, California |
Users: | 1,067 |
Nodes: | 17 (0 / 17) |
Uptime: | 07:20:46 |
Calls: | 501,254 |
Calls today: | 1 |
Files: | 109,407 |
D/L today: |
811 files (4,849M bytes) |
Messages: | 302,002 |
Posted today: | 1 |