3 ms·
You can also "forbid" others from reading and writing your file if use a new temporary file they don't know about, and weakly enforce that by removing the file
by jo909 10y ago
You can also "forbid" others from reading and writing your file if use a new temporary file they don't know about, and weakly enforce that by removing the file system entry with unlink while keeping the fd open, then link it again later.
Part of the goal is IMHO not having to write out the entire file every time, only because you changed a few bytes. The atomic renaming can't do that, to my knowledge.
I'm really only wondering about the forbidding reads part, and if that gains anything useful. For a process that knows about and participates in the locking process that's already possible, but mandatory file locks are also for processes that did not participate. Like for example cat, the backup process etc.