Accept Error : Too many open files

Posted on 1999-07-22
Medium Priority
Last Modified: 2010-05-18
Hi !

Running Solaris on a Sun Ultra we are getting an error from accept() stating that there are too many files open.
How can we avoid this, we have tried setting the number of file descriptors by using ulimit -n from 64 to 128, but this makes no difference.
Question by:checkin
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: 1263790
How many files do you have open at a time?
Can you close unused files?


Author Comment

ID: 1263791
the application is a server which accepts connections to clients, a single client can open 30 connections which last for about 3 seconds before they are closed.
At the momment we can not get over 2 clients connecting simulateously without getting the error from accept of too many files open.  We are connecting using Unix Domain Sockets.

Expert Comment

ID: 1263792
Where is your accept()?  Are you forking for each call?  Have you tried making multiple processes that run fulltime,
one for each line in (or however many you want to handle at once), and using pipes to them for handling the transactions?  I guess the last question is really trying to find out if your process is complaining about too many open, or the OS is complaining.  If the latter, is there an OS install parameter you have set too small?  A sample of your handler which opens 30 redone to execute by itself, and hold them open until killed, could be run as many times as you need simultaneously to give you more info and tell you when you have the problem solved.

Accepted Solution

FKern earned 200 total points
ID: 1263793
As you probably know, in Unix, sockets are actually special purpose files.  Some flavors of Unix have one or more kernel configurable parameters for the max number of files open for any single user and/or system wide at any given time.  Now since the accept takes the open request from the master (listen) socket and spawns a slave socket to handle the transaction, this is actually creating another open file.  There are a couple of things that you will want to look at:

Q)   Ref: (The application is a server which accepts
          connections to clients, a single client can
          open 30 connections which last for about 3
          seconds before they are closed.)
A)   You may only open 30 connections at a time, but
          they don't just go away when they are closed.
          They actually go into a close(time) wait state
          for a short while.  So when you do you next 30
          connections, the first 30 may not have timed
          out and been released to the OS yet.

1) Is the max open files configurable in your kernel?  By default this is set low (usually 64, they were not  thinking about sockets when they set this default... only actual user files).  If so, set it high (I suggest 1024), this will not degrade performance only give your application a little more leaway to do what it need to to get the job done.  If this is not configurable, then there is no limit (aix is like this).


Are you running as root or normal user?
Are you running as a daemon or normal application?

2) You may want to look at using shutdown() instead of close().  shutdown() seems to release the socket back to the OS quicker.


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.

Question has a verified solution.

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

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.
Suggested Courses

719 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