File Descriptor Limits#

A descriptor, also commonly called a file handle is an object that a program uses to read or write an open file, or open network socket, or a variety of other devices. It is represented by an integer, and you may be familiar with stdin, stdout, and stderr which are descriptors 0, 1, and 2 respectively.

Normal programs don't open up many descriptors at all, and so there are some latent problems that you may experience should you start running applications that require many descriptors to be used.

Operating systems enforces a limit on the number of descriptors that a program can have open at a time. There are typically three limits involved here. One is a kernel limitation, depending on your operating system you will either be able to tune the number of descriptors available to higher numbers (this is frequently called FD_SETSIZE). Or you may be stuck with a (relatively) low amount. The second limit is called the hard resource limit, and it is sometimes set by root in an obscure operating system file, but frequently is the same as the kernel limit. The third limit is called the soft resource limit. The soft limit is always less than or equal to the hard limit.

For example, the hard limit may be 1024, but the soft limit only 64. Any user can raise their soft limit up to the hard limit. Root can raise the hard limit up to the system maximum limit. The soft limit is the actual limit that is used when enforcing the maximum number of files a process can have open.

To summarize:

  1. open files <= soft limit <= hard limit <= kernel limit

You control the hard and soft limits using the limit (csh) or ulimit (sh) directives. See the respective man pages for more information. For example you can probably use ulimit -n unlimited to raise your soft limit up to the hard limit. You should include this command in a shell script which starts your application.

Unfortunately, it's not always this simple. As mentioned above, you will probably run into some system limitations that will need to be worked around somehow.

To view the file descriptors limits (soft and hard limits)

/usr/bin/ulimit -n (soft limit) /usr/bin/ulimit -H -n (hard limit)

Change File Descriptor Limits:#


Any user can set the soft limit up to the hard limit for their session, but only root can increase the system hard limit. On Solaris, the default soft limit is 256, and the default hard limit is 1024.

To change these defaults, edit /etc/system and add the following lines:

Increase system file descriptor limits

  • set rlim_fd_cur = 256
  • set rlim_fd_max = 4096

The first one sets the soft limit (the example actually keeps it at the default) and the second line icreases the default hard limit from 1024 to 4096.

Reboot the system for the changes to the hard limits to take effect.

Add new attachment

Only authorized users are allowed to upload new attachments.
« This page (revision-1) was last changed on 24-May-2008 13:26 by UnknownAuthor