I need to create a file that is locked against reads, at the point of creation, so that other processes that may go looking for this file do not start reading it, before it has been completely written.
I know that I can create and then lock it, but I’m concerned that this leaves me open to a race condition.
Or am I worrying about nothing here? If I have a file open for writing and then open it for reading with another process, will the reading process never see an EOF until the writing process closes the file?
There’s is a race condition with
>and>>, but it can be circumvented using+<.There is also a race condition in the scenario you describe.
A common strategy to avoid this problem is to have the writer
renamethe file into the directory the reader monitors when the file is complete.renameis an atomic action, so the file will appear fully formed in the directory the reader monitors. This requires the cooperation of the writer, but the best solutions will.