Open a file in add mode in several ways

AFAIK each process will maintain a separate file table (correct me if my understanding is incorrect). So, for example, the same file is opened in APPEND mode by several processes at a time, and each process writes some data to the file. It is added to the end of the file correctly. So can someone explain to me how the file table in all processes is updated at a time? thanks in advance

+4
source share
2 answers

I do not think file tables are being updated. It is just that the file system “searches” to the end of the file before writing.

Since unrelated processes are allowed to write to the end of the file at the same time, I believe that you need to use some kind of lock, the search and the actual recording should not be interrupted.

This add mode is very similar to a specific file system, not to the functionality of the operating system. I well remember that in Linux O_APPEND does not work correctly if the file is in NFS.

+4
source

APPEND mode works by searching to the end of the file before recording (as opposed to recording in the CURSOR position, otherwise). Since the end of the file is a property of the file, not the file table, all processes will be added to the end of the file.

0
source

All Articles