I need to create a file if it does not exist, in a way that another process trying to create this file would fail. I need the file be considered "created" even before the creating process finished writing the actual data to it.
I read about O_EXCL
flag to open()
, so it seems that the solution exists, I have a few questions however:
- do you have experience with this technique? How good is it? (I guess I can't have a DB-level atomicity, but but good enough is... well, enough)
- should I immediately close the file after
open()
so that it is considered created, and then reopen it for writing? - are there any subtleties to be aware of?