0

I'm creating a C application daemon that I want to be able to interact with through named pipes. For example, I write in the shell echo hello > /tmp/appname/interface, and the application reads it and does stuff with what I just echoed into the named pipe.

I've successfully managed to implement this with a singular named pipe with read(). However, I want to be able to listen to many different named pipes at the same time. I don't think spawning a new thread for each named pipe is a very good solution. I am also concerned about whether constantly listening for something to be written to the named pipes with read() will use an unnecessarily high amount of CPU. Is there a better way to approach this?

Accumulator
  • 873
  • 1
  • 13
  • 34
  • Here's a link that can interest you: [how to read multiple serial ports in realtime in C or Python](https://stackoverflow.com/questions/57234078/how-to-read-multiple-serial-ports-in-realtime-in-c-or-python). This is about serial ports but you may hit the same problem. – Missu Nov 16 '19 at 07:33
  • read is a blocking read - doesn't use a lot of cpu - it just sits there. If you are polling, then it will use a lot of CPU. If you are using a blocking read then the only way to listen to multiple pipes is by using threads. Also do a stack overflow search on how to terminate blocked I/O. – cup Nov 16 '19 at 07:36

0 Answers0