my correction to above -> c does abide to the fpc fpflock when flock is actually used in my c code (i had said it didn't because the code i used didn't have flock in the version i mistakenly used) (i wonder if fortran wil abide as well)
It's not really a question of language but of whether the other program also uses flock (or fcntl) to try to lock the file. In that case the call will return the corresponding error (or lock while waiting). If the other program doesn't care and just goes on with the writing (or reading) the system will hapily go and obey its orders. That's why they are called
advisory locks.
Locking and respecting locks is seen (quite rightly) as the programmers' responsabilty. The problem is that while almost each file write (and not a few of the reads!) should be locked (remember, this is a multitasking
and multiuser system), lots of programmers don't care about it or don't even
know what "this thing" is for.
It's a lot like what happens with "coperative" multitasking (hey, Windows 3, hi!): if programs don't "cooperate" there is no multitasking
thank you for the code - i'll change the form to a nice silver color though
This system does that automatically
https://www.kernel.org/doc/Documentation/filesystems/mandatory-locking.txt <-- perfect for explaining all thanks for the information
Lots of little gems like that "hidden" there
i will program fcntl/fpfcntl vs flock/fpflock code (just to see if i can do it and to see if it any faster? will it? once compiled?
Probably minimally or not all: Take into account that
fcntl() can do a lot more things than
flock() so just deciding what it has to do may even make it slower.
thanks for the heads up about inserting quote
My pleasure.
but is fpaccess faster then fileexists ? i would guess so but once compiled would it matter?
Again, probably not or minimally. All you really avoid (in LInux) is a call to FileExists(), which turns around and calls fpaccess to do the job. A matter of microseconds, at most, and you'd loose the multiplatform capacity.
Your program now is not multi-platform, if you're using
flock(), but if some day you need to convert it to, say, Windows <shudder> that's one less place that would give you problems.
The rule of thumb for this kind of things is: if there's a platform-independent way to do something, use it; if not, $ifdef it