Reputation: 2605
AFAIK each process will maintain separate file table (correct me if my understanding is wrong). So for example same file is opened in APPEND mode by multiple processes at time and each process is writing some data to the file. It gets appended at end of file correctly. So can anyone explain me how file table in all the processes gets updated at a time? Thanks in advance
Upvotes: 4
Views: 1874
Reputation: 10028
The way APPEND
mode works is by doing a seek to the end of the file, before writing (as opposed to writing at the CURSOR
position, otherwise). Since the end of the file is a property of the file and not of the file table, all the processes would be adding to the end of the file.
Upvotes: 0
Reputation: 182619
I don't think the file tables are updated. It's simply that the filesystem "seeks" to the end of the file before writing.
Since unrelated processes are allowed to write to the end of file at the same time, I believe some sort of locking must be involved, the seek and the actual write must not be interrupted.
This append mode is very much a feature of a particular filesystem, not a feature of an operating system. I remember clearly that on Linux, O_APPEND
doesn't do the right thing if the file resides in NFS.
Upvotes: 4