I have heard that the mv command in linux is atomic. But does that mean we can safely read the file? Will we always see the content after the mv command is completed?
I have the following scenario. I have different processes responsible for writing and reading a file. I have one process that is periodically running mv a.txt b.txt and another process that is periodically running cat b.txt. My question is, will cat b.txt always avoid seeing partial file content? I.e. will it always see the content of b.txt before or after the mv command (and not in between the write)? I think many os uses separate key for read and write, so I am not sure if this process (mv in parallel with cat) is safe.
My other question is - if it is not safe to run mv and cat in parallel, then what can I do to ensure safety? Will I need to explicitly use lock the file myself (using fcntl or something else)?