0

Blockquote

how does O.S know that writer is still writing. ?... What is workflow of EOF for file(closing file handle like ^D or ^z) ? what happens if EOF is never written ?

what happens if readers reading rate is faster than writer's writing speed ? Can a rate mismatch result in deadlock ?

what can be other unwanted scenarios ?

How does O.S calculate EOF while reading file ?

-Nikhil

P.S: Current Operating system is windows but I don't mind learning interesting feature for the same on unix too.

Blockquote

More Edits and More info on the Question

Now that I know EOF is no character,So it cannot be written on the data of file. IF O.S. determines the EOF using File_size like what even @saurabh pointed.

(->) EOF while Reading ( Would probably be determined from file size which would stored in drive table of appropriate File system) )

  • So does process keeps polling File table for file size to determine EOF as there could be cases of not-fixed files size.
  • To my little knowledge, EOF is encountered when you read beyond the EOF(in our case file-size). Assume a situation where writer is writing intermittently and reader is reading blocks. SO if reader tries to read more than the available chunk would EOF be thrown ? But Writer has not signalled EOF yet ?
Niks
  • 1
  • 3
  • For files, there is no special byte or byte-sequence that means end-of-file. A program writing to a file can write any time it want as long as the file is open, the OS will only know the program is done with the file when it is closed. – Some programmer dude May 28 '12 at 07:00
  • Finally,I did find this post very useful for explaining the eof part and its workflow. [can-we-write-an-eof-character-ourselves](http://stackoverflow.com/questions/3061135/can-we-write-an-eof-character-ourselves) . especially post by @b-gen-jack-o-neill – Niks May 28 '12 at 17:14

2 Answers2

0
  1. Untill the program dont close the file. OS assumes that the file can be read/written or both (depends on the mode of opening the file).

  2. EOF is nothing, but OS knows it from the size of file. Lets say, your file is of size 100 bytes, and you asks to read from byte 99 and asks for 6 more bytes, then OS knows that file is till only 100th bytes, so it will return EOF.

  • Thanks mate !. Adding on 2 point. If O.S determines EOF from File size, what happens if file size is not known. Or perhaps changes dynamically (content gets added)?. – Niks May 28 '12 at 11:07
0

If you are writing to a file from one process and reading from it from another, you may want to look into using pipes instead. Those are special files designed exactly for your purpose: you can only write at one end, read at the other end and the reader blocks or is notified if there isn't any data to read...
And yes, there is no special EOF marker. If using normal files and you don't like headaches much, just don't mess with them simultaneously from multiple processes.

Torp
  • 7,924
  • 1
  • 20
  • 18