Operating System - HP-UX
1753287 Members
5609 Online
108792 Solutions
New Discussion юеВ

Re: Why would select() block if descriptor i want is readable?

 
SOLVED
Go to solution
someman
Occasional Contributor

Why would select() block if descriptor i want is readable?

Program is supposed to be simple
monitor for processes. Master process creates supervisors that will execute
tasks. master will communicate with supervisors using pipes. supervisor
will tell master about state of running task, master can tell supervisor misc commands.

Master periodically writes to supervisor's pipe and it have to respond.
I want to use select() in master to wait for responce from supervisor.
What happens is that select() blocks, although supervisor had written
responces to corresponding descripotr. If i just read from it, it has data.
Where can be an error? I don't understand.
Code is attached. Currently i'm running this on linux, but will need it on hpux too.
2 REPLIES 2
rick jones
Honored Contributor
Solution

Re: Why would select() block if descriptor i want is readable?

You need to go back and re-read the select() manpage and/or other select() documentation:

Your code reads:
ret = select(1, &rfds, NULL, NULL, &tv);

which is all well and good if the only FD in which you are interested is FD 0 - the "nfds" parameter is supposed to be one higher than the number of the highest file descriptor set in readfds, writefds or errorfds. From the HP-UX 11.11 manpage for select():

"The nfds argument specifies the range of file descriptors to be tested. The select() function tests file descriptors in the range of 0 to nfds -1."

You might also want to consider lookint at more than one FD at a time in that loop - from a quick glance, it appears you are iterating one at a time through all the fds which is not going to be terribly efficient, and delays with one supervisor will affect the code's ability to process traffic from the others.
there is no rest for the wicked yet the virtuous have no pillows
someman
Occasional Contributor

Re: Why would select() block if descriptor i want is readable?

Thank you! I have to read docs more carefully.

>>it appears you are iterating one at a time through all the fds which is not going to be terribly efficient, and delays with one supervisor will affect the code's ability to process traffic from the others.

I've just started and this is more a stub to test what i want than real application. Thanks anyway.