English 中文(简体)
关于 EOF 和阅读器/文字同步
原标题:About EOF and Reader/Writer synchronization

块角

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 ?

如果读者阅读率比作家写作速度快,会怎样? 汇率错配会导致僵局吗?

其他不想要的情况又会是什么?

O. S 读取文件时如何计算 EOF?

- 尼基尔

P. S. : 当前操作系统是窗口, 但我不介意在 unix 上学习同样有趣的功能 。

块角

<强度 > 更多编辑和关于问题 的更多信息

现在我知道EOF不是字符, 所以它不能写在文件的数据上。 IF O. S. 使用文件大小来决定 EOF, 就像 @saurabh 指点的一样 。

( & gt;) 读取 < / 强 > 时 < 强 > EOF (可能根据文件大小确定,文件大小将存储在相应文件系统的驱动器表格中) )

  • 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 ?
问题回答
  1. 直到程序不关闭文件。 OS 假设文件可以读/ 写或两者兼有( 取决于打开文件的模式 ) 。

  2. EOF不算什么,但OS从文件大小中知道。让我们说,您的文件大小为100字节, 您要求从字节 99 中读取, 并要求增加 6 字节, 然后OS知道该文件直到第100字节, 所以它会返回 EOF 。

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.





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签