• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 228
  • Last Modified:

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.
0
xyrus
Asked:
xyrus
1 Solution
 
KocilCommented:
No idea mate,
I haven't seen your code.
0
 
oferhCommented:
does the select return when a client is connecting?

about your memory leaks:
1. you can use a utility like purify to check for them.
2. you can create a custom new and delete operators,
   or do your malloc and free through another function
   to trace all your memory allocations. see an example in:
   http://www.embedded.com/story/OEG20020222S0026
0
 
Kent OlsenData Warehouse Architect / DBACommented:
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
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
xyrusAuthor Commented:
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.
0
 
adijaCommented:
Does it hang everytime or only sometimes?
0
 
xyrusAuthor Commented:

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.

0
 
xyrusAuthor Commented:
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.  
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now