ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
I have an application where there is a reader process that reads data from fifo and multiple writer processes that writes data into the fifo. Both read and write are non blocking.
Everything works fine until suddenly a situation like below happens:
Writer writes n bytes into the fifo but the reader returns saying no data to be read. This is very strange.
I also doubt that there is some kind of stack corruption inside the process memory but the process doesnt crash but it just continues doing its work. So my doubt is after that memory corruption, if the process reads from FIFO, it returns saying no data read until the process is restarted. After restarting everything works fine again.
Can there be a case where a corruption in process memory affect the FIFO also?
I believe FIFO queues may buffer input until the buffer gets above a certain size. Therefore, when read it appears the buffer is empty. The reason for this (I think) is speed as there would be a large overhead writing every chunk of data out instantly. You can flush the buffer after writing to force the data to be made available. Do you flush?
The writer process opens fifo in O_WRONLY|O_NONBLOCK|O_SYNC. The O_SYNC flag takes care that the data is written to the underlying stream otherwise blocks the process. This is how i make sure that the data is written into the fifo, rather than flushing it.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.