Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

is there any way to read one number from the anonymous pipe in two different processes?

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading