Operating System - HP-UX
1833867 Members
1969 Online
110063 Solutions
New Discussion

Read(2) command going for infinite sleep

 
Channabasappa Herur
New Member

Read(2) command going for infinite sleep

Hi All,
Our application is hanging because "read(2)" command is going for a infinite sleep.

Following is the "read" system call used by our application

read (accept_h, tmp, buffleft)
where accept_h - Socket File descriptor
tmp - Buffer of 102400 bytes
buffleft - 102400

Following is the output of the tusc tool

read(4, 0x40022630, 102400) ..................................................... [sleeping]

The above line indicates that read command is infinetly sleeping.

Please let me know when can a "read(2)" command go for a infinite sleep ? I have attached the tusc tool output for reference.

Thanks and Regards

Channabasappa Herur


2 REPLIES 2
A. Clay Stephenson
Acclaimed Contributor

Re: Read(2) command going for infinite sleep

Do a man 2 read and a man 2 accept -- that will really explain it. This is normal behavior when O_NONBLOCK is clear and no data are available. There are various means of handling this; among them are 1) use non-blocking i/o, 2) use a SIGALRM signal handler.


If it ain't broke, I can fix that.
rick jones
Honored Contributor

Re: Read(2) command going for infinite sleep

...or select(), or poll(), or eventports (man 7 poll)

Even if you "know" that the thing to which you have connected is going to send you data spontaneuously after you have connect()ed to it, there is no guarantee that data will actually reach you.

And while there are some servers that do emit data spontaneously, it is much more common that once you connect to them, you have to send them some sort of explicit request first.
there is no rest for the wicked yet the virtuous have no pillows