FIFO question
Hello,
This is the first time I am using named pipes. I have a process with this C++
code that creates a named pipe and loops on writing the character "2" to it.
stringstream ssbuffer;
string buffer;
int pipeFD;
while (true){
pipeFD = open("my_pipe", O_WRONLY);
ssbuffer << 2;
buffer = ssbuffer.str();
write( pipeFD, buffer.c_str(), 1 );
close(pipeFD);}
It happily sits on the pipe. When I open up another console and type "catmy_pipe" it prints an arbitrary number of 2s. Usually many tens of them. From what I read I thought that when I close the pipe using the close() call then the readers will quit. Furthermore the main program doesnt receive a broken pipe after the reader quits like it should. This is test code and I want just ONE "2" to be read by cat. Perhaps I am missing something simple? Can anyone enlighten me?
I plan to have only one reader and one writer on the pipe at a time so synchronization is not neccesary.
I have also tried nanosleeping after the close. It seems sleep(1) fixes the problem, but the main program still doesnt get a broken pipe after cat exits and this causes an unacceptable and unpredicate delay before the start of the read.
Futhermore I have also tried writing a very simple read program that tries to read 10 bytes from the FIFO. It succeeds and actually gets 10 bytes from the FIFO! Shouldnt the read be short because the main program called close after 1 byte?
----------------------------------------
--EB
Quoted 4 lines
All is fine except that I can reliably "oops" it simply by trying to read from
/proc/apm(e.g. cat/proc/apm).
oops output and ksymoops-2.3.4 output is attached.
Is there anything else I can contribute?
The latitude and longtitude of the bios writers current position, and a ballistic missile.
--Alan Cox LKML-December 08,2000
----------------------------------------
-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Fixed it.
Quoted 5 lines · Eric Bambach
Hello,
This is the first time I am using named pipes. I have a process with this
C++ code that creates a named pipe and loops on writing the character "2" to it.
---snip---
----------------------------------------
--EB
Quoted 4 lines
All is fine except that I can reliably "oops" it simply by trying to read from
/proc/apm(e.g. cat/proc/apm).
oops output and ksymoops-2.3.4 output is attached.
Is there anything else I can contribute?
The latitude and longtitude of the bios writers current position, and a ballistic missile.
--Alan Cox LKML-December 08,2000
----------------------------------------
-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html