FD maximum and limit

Source: Internet
Author: User

The number of FD determines the maximum value of FD.

 

In Linux, the total number of FD enabled by the system is:

/Proc/sys/fs/file-Max, depending on the memory

The file-Max file/proc/sys/fs/file-Max sets the maximum number of file-handles that the Linux kernel will allocate. we generally tune this file to improve the number of open files by increasing the value of/proc/sys/fs/file-Max to something reasonable like 256 for every 4 m of ram we have: i. e. for a machine with 128 MB of RAM, set it to 8192-128/4 = 32 32*256 = 8192.

/Proc/sys/fs/file-Nr records the usage of FD in the system, and the number of allocated file handles
Number of file handles used
Maximum number of file handles,

The maximum number of FD opened by a single process is ulimit-N. You can use sysconf (_ SC _open_max) to obtain the default number of FD opened processes.

To modify the FD limit, you can first modify the shell's ulimit-N,

You can also use the setrlimit function to modify the settings:

Void modifyfdlimit ()
{
Rlimit fdlimit;

Fdlimit. rlim_cur= 30000;
Fdlimit. rlim_max = 30000;

If (-1 = setrlimit (rlimit_nofile, & fdlimit ))
{
Printf ("Set max FD open count Fai./nl ");

Char cmdbuffer [64];
Sprintf (cmdbuffer, "ulimit-N % d", 30000 );

If (-1 = System (cmdbuffer ))
{
Printf ("% s failed./N", cmdbuffer );

Exit (0 );
}

If (-1 = getrlimit (rlimit_nofile, & fdlimit ))
{
Printf ("ulimit FD number failed .");

Exit (0 );
}
}

// Printf ("Hard limit: % d. Soft limit: % d", fdlimit. rlim_max, fdlimit. rlim_cur );
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.