Hanging at select function call

Posted on 2003-03-25
Medium Priority
Last Modified: 2010-04-15
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.
Question by:xyrus
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 8208230
No idea mate,
I haven't seen your code.

Accepted Solution

oferh earned 150 total points
ID: 8209505
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:
LVL 46

Expert Comment

by:Kent Olsen
ID: 8210252
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.


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.


Author Comment

ID: 8214843

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.

Expert Comment

ID: 8224151
Does it hang everytime or only sometimes?

Author Comment

ID: 8235735

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.


Author Comment

ID: 8236192
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.  

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question