I have one anonymous pipe and two child processes. I write one number in the pipe and now i have to read it in both processes. is there any way?
I tried to GetStdHandle(STD_INPUT_HANDLE), also I tried to use cin.peek but it doesn’t work for me.
>Solution :
You don’t tell us which kind of anonymous pipes you’re dealing with. However, since pipe is a UNIX concept in its core, I’ll assume you’re referring to POSIX pipes.
These don’t support multi-reader access. A read access necessarily consumes the read bytes from the underlying buffer.
So what you want is impossible, kind of by design.
However, reading that you have two child processes, it would seem sensible to assume you could use shared memory for the actual data exchange, and some other means for synchronization of access.