Link to home
Start Free TrialLog in
Avatar of xyrus
xyrus

asked on

Hanging at select function call

Good day.

I am working on a program that forks into 5 separate processes on startup.  Afterwhich, each of the process wait for a connection from a client socket and whoever accepts the client connection first handles the communication with the client.  My problem is that the program would occasionally hang at the select function.  I have called on FD_ZERO and FD_SET before the select function and also I have set the wait time to 10 microsecs.  Anyone here has any idea on why the program "hangs" on select?  My theory is there could be a possible memory leak in my program but I want to get other feedback.  Also, anyone here can suggest what I could do to debug the memory leak?  I have tried tracing the code and all my mallocs have corresponding free memory.  Any other ideas?

Thanks a lot.
Avatar of Kocil
Kocil

No idea mate,
I haven't seen your code.
ASKER CERTIFIED SOLUTION
Avatar of oferh
oferh

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Kent Olsen
Based on your description, it sounds like you've got 5 tasks listening on the same port.  If so, you've got 5 processes all trying to establish simultaneous connections to the same "entity" and something as subtle (and uncontrollable) as exactly when a tasks CPU "time-slice" expires may be at the heart of the problem.

You should have 1 task monitoring the socket and when a connect occurs THEN fork the task.


Kdo
Avatar of xyrus

ASKER

oferh,

the select is not used for when the client is connecting.  i have no problems with the connection part, the select is used for receiving the data from the client AFTER the connection has been established.  i use it to get all the data sent by the client.

thanks for the info on memory leaks.  i will be checking out the link you specified.  thanks.
Does it hang everytime or only sometimes?
Avatar of xyrus

ASKER


Usually it hangs after some number of client connections.  This is why I think maybe there is a memory leak.  But maybe there are also other factors or subtleties I failed to consider.

Avatar of xyrus

ASKER

It seems that during my course of debugging other problems with the program, this particular hanging problem has been fixed since the program does not seem to hang anymore. I've thus decided to give the points to oferh since he gave me some help for the memory leaks.  I am still going to check the memory leaks though, just in case.  Besides my request for an internet connection here at the office will soon be expiring so I may not be able to give away the points so I am doing it now.  Thanks to all who've responded.