I think you're confusing things. File locks in POSIX do not influence the ability to open files at all. File locks only influence the ability to create other locks.
In other words, file locks are normally* cooperative, if some program doesn't try to lock a file, it can bypass all locks.
In other words again, my sample code is correct; you open the file for append (or you can use some other non-destructive open) and lock after that (but before writing).
If this doesn't help, please show some code or explain what you're trying to do, because right now it just looks like you don't know what file locks do and don't do on UNIX.
* Update: some unix systems also provide mandatory locks. I'm ignoring those since a) they're not portable and b) I don't like mandatory locks.
|