in reply to while(select())

What are you trying to do? Typically one uses select for one (or a combination) of the following: Your program doesn't do either. It waits at most 0.2 seconds for a single handle to become availble, and then you read from it, without checking whether it actually has data on it, or whether the select timed out. You also don't check whether sysread encountered an error, or eof.

Since I can't guess the intend of your program, I won't offer an alternative.